如何在MATLAB中正确旋转椭球?

问题描述

我试图创建,旋转然后将椭球平移到两个点的中间(例如:(0,0)和(100,100,100))。

%set up figure
figure
xlabel('x')
ylabel('y')
zlabel('z')
grid on

%create ellipsoid at origin with:
%x semi-axis = 10,y semi-axis = 3,z %semi-axis = 3
[x,y,z] = ellipsoid(0,10,3,30);

%create surface out of ellipsoid
h = surf(x,z);
hold on

%rotate surface -45 degrees on Y axis (Pitch)
rotate(h,[0 1 0],-45);

%rotate surface 45 degrees on Z axis (Yaw)
rotate(h,[0 0 1],45);


%get X,Y,Z data points for translation
ch = get(gca,'children');
X = get(ch,'Xdata');
Y = get(ch,'Ydata');
Z = get(ch,'Zdata');

%create two points: one at origin,the other at (100,100)
pointA = [0 0 0];
pointB = [100 100 100];

%translate ellipsoid to midpoint between pointA and pointB
X = X + (pointA(1) + pointB(1))/2;
Y = Y + (pointA(2) + pointB(2))/2;
Z = Z + (pointA(3) + pointB(3))/2;

%plot rotated+translated ellipsoid
surf(X,Z);

%remove original ellipsoid from figure
delete(h);
hold on

%create and plot line from (0,0) to (100,100)
lineX = [ pointA(1) pointB(1)];
lineY = [ pointA(2) pointB(2)];
lineZ = [ pointA(3) pointB(3)];

plot3(lineX,lineY,lineZ);

这是我的结果

result

如图所示,椭球的垂直旋转未与从(0,0)到(100,100)的线对齐。

我在做什么错了?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)