【问题标题】:Rotate 3D Surface until Level on MATLAB在 MATLAB 上旋转 3D 表面直到水平
【发布时间】:2017-08-07 02:44:05
【问题描述】:

我还没有开始创建代码,因为我有点卡住了,需要一些帮助来指导我朝着正确的方向前进。我必须使用 MATLAB 来解决以下问题: 我得到一个 3D 表面(大约 300 个点)的 x,y,z,它围绕 x 轴倾斜任意角度 theta,并围绕 y 轴倾斜任意角度 alpha。目标是倾斜表面,使所有 z 值都相同,这意味着表面是水平的。

我尝试过使用旋转矩阵,但它并没有达到我的预期。非常感谢任何建议和想法。

【问题讨论】:

    标签: matlab 3d


    【解决方案1】:

    这并不优雅,但您可以尝试通过围绕 x 和 y 轴以设定的增量旋转图形来强制解决方案。然后,只需采用 z 坐标的最大数量在窄范围内的解决方案。这意味着表面大致是水平的。

    【讨论】:

    • 这就是我的想法,但不确定是否有更“优雅”的方式来解决这个问题。感谢您的建议!
    【解决方案2】:

    一种类似但更正式的方法是计算平行于表面的向量并知道该向量的方向,c=norm((a,b,c))*cos(angle) 非常容易获得旋转参数。

    如果你有一个类似平面的表面,你可以将它拟合到平面方程a*x+b*y+c*z+d=0 并且垂直于平面的向量是(a,b,c)

    如果您有另一种类型的表面(通常是这种表面),您可能仍然会发现平面的矢量很有用,因为平面可能与表面平行,或者可能给出比较的方向以使旋转。

    根据你的实现方式,它只会在原点 (0,0,0) 处旋转。如果您的飞机远离原点,则两个数字将彼此远离。一个简单的翻译就可以解决。

    在飞机周围有一些随机点,我得到了它:

    使用我使用的代码。

    n=300; 
    x= 20.*rand(n,1)-10; %interval
    y= 20.*rand(n,1)-10; %interval
    %if you want to plot a plane
    z=(2*(y+rand(n,1)*0.3)+2*(x+rand(n,1)*0.3)-7)/.4+rand(n,1)*0.3;
    
    figure()
    
    plot3(x,y,z,'.')
    hold on
    
    %here i put the plane average data on zero
    Centerplane=[mean(x) mean(y) mean(z)];
    xc=x-mean(x); 
    yc=y-mean(y);
    zc=z-mean(z);
    
    %get the 'a' and 'b' component of the plane equation (z=a*x +b*y +d)
    A=[xc yc]; B=zc;
    r=A\B %%%Matlab!
    r = vrrotvec( (([r(1) r(2) 1]/norm([r(1) r(2) 1]))),[0 0 1]);
    RM=vrrotvec2mat(r); %get the rotation matrix
    rdata=[xc,yc,zc]*RM; %rotate data
    
    % put in the proper position back
    rt_c_x=rdata(:,1)+mean(x);
    rt_c_y=rdata(:,2)+mean(y);
    rt_c_z=rdata(:,3)+mean(z);
    
    %and plot
    plot3(rt_c_x,rt_c_y,rt_c_z,'c.')
    
    A=[x y]; B=z; %default data
    r=A\B %%%Matlab!
    r = vrrotvec( (([r(1) r(2) 1]/norm([r(1) r(2) 1]))),[0 0 1]);
    RM=vrrotvec2mat(r); %get the rotation matrix
    rdata2=[x,y,z]*RM; %rotate data
    
    %and plot
    plot3(rdata2(:,1),rdata2(:,2),rdata2(:,3),'g.')
    
    xlabel('X')
    ylabel('Y')
    zlabel('Z')
    

    【讨论】:

      猜你喜欢
      • 2013-07-07
      • 1970-01-01
      • 2013-07-29
      • 2011-01-06
      • 2011-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多