更改预定义的轴

时间:2016-08-19 11:45:59

标签: matlab matlab-figure cad

我有一张图片来自CAD数据,我在MATLAB中打开它。我想要做的是将图形旋转90度并更改轴,如图所示。

enter image description here

我以stl格式保存了图形,并使用以下链接中的代码将其打开为matlab图形。

https://de.mathworks.com/matlabcentral/fileexchange/3642-cad2matdemo-m

问题:

  1. 我没有任何函数或m文件来重新生成图形。如何旋转图中的轴?

  2. 如何获得图中的所有积分位置?

  3. 提前致谢。

1 个答案:

答案 0 :(得分:0)

如果你没有办法重新生成图形数据,但仍然有一个包含数据的MATLAB图形,你可以检索它们。

我首先创建一个示例图形对象(patch,由您链接的函数返回):

R = 3 ; nFaces = 5 ;
tt = linspace(0,2*pi,nFaces+1).' ; tt(end) = [] ;

[x,y] = pol2cart(tt,zeros(nFaces,1)+R) ;
hp = patch(x,y,'b') ;
axis equal

pentagon

现在,如果图形是活动图形(如果您想确定,请单击图形以使其聚焦),您可以查询内部绘制的数据。

首先,我们需要获取当前图形的axes中显示的所有图形对象的句柄:

% get handle of all graphic objects in the current axes
hlist = get(gca,'Children')

hlist = 
  Patch with properties:

    FaceColor: [0 0 1]
    FaceAlpha: 1
    EdgeColor: [0 0 0]
    LineStyle: '-'
        Faces: [1 2 3 4 5]
     Vertices: [5x2 double]

在我的情况下,只有一个对象,所以没有歧义。如果返回了多个句柄,请在patch个对象中进行选择(与每个对象一起玩,找出哪个是什么)。

识别出要访问的对象后,是否可以轻松旋转:

% only one object in this case but if there was several in the list I
% would isolate the object I want to manipulate. 
hp = hlist(1) ;

% to rotate the graphic object "hp", around axis Z ([0 0 1]), by 90 degrees.
rotate( hp ,[0 0 1] , 90 )

pentagon rotated

或检索点的坐标:

% to get the points coordinates:
pc = get(hp,'Vertices')

pc =
   0.286474508437579   2.713525491562421                   0
  -2.566695040447882   0.640576474687264                   0
  -1.476881248439841  -2.713525491562421                   0
   2.049830265314998  -2.713525491562421                   0
   3.139644057323040   0.640576474687263                   0

请注意,我检索到的坐标,带有XYZ坐标(列)的5点(线)是后的坐标轮换。如果您需要原始坐标,则必须在将旋转应用于对象之前查询它们。

更多阅读:

相关问题