0
所以我有一個對象,我對它應用了旋轉,我很好奇如何讓它沿着路徑移動。我仍然在學習MatLab,所以如果你看到任何我能/應該做的不同的事情,請讓我知道。 任何幫助表示讚賞。在MatLab中沿着路徑移動三維對象
kittyx = [0 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 ...
150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 ...
-150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 ...
-150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 -150 150 150 -150 150 150 230 150 150 230 150 150 230 ...
150 150 230 150 150 230 150 150 230 150 150 230 150 150 230 150 150 230 150 150 230 150 150 230 150 150 230 150 150 230 150 150 230 150 150 230 ...
150 150 230 150 150 230 150 150 230 150 150 230 150 150 230 150 150 230 150 150 230 150 150 230 150 150 230 150 150 230 150 150 230 150 150 230 ...
150 150 230 150 150 230 150 150 230];
kittyy = [0 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 7.5 7.5 8 8 8.5 8.5 9 9 9.5 9.5 10 10 10 10 10 10 10 10 10 10 10 10 10 10 ...
10 10 10 10 10 10 10 10 9.5 9.5 9 9 8.5 8.5 8 8 7.5 7.5 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0 -1 -1 -2 -2 ...
-3 -3 -4 -4 -5 -5 -6 -6 -7 -7 -7.5 -7.5 -8 -8 -8.5 -8.5 -9 -9 -9.5 -9.5 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 ...
-10 -10 -10 -10 -10 -10 -9.5 -9.5 -9 -9 -8.5 -8.5 -8 -8 -7.5 -7.5 -7 -7 -6 -6 -5 -5 -4 -4 -3 -3 -2 -2 -1 -1 0 0 0 -7 0 7 6.5 0 6 5.5 0 ...
5 4.5 0 4 3.5 0 3 2.5 0 2 1.5 0 1 0.5 0 0 -.5 0 -1 -1.5 0 -2 -2.5 0 -3 -3.5 0 -4 -4.5 0 -5 -5.5 0 -6 -6.5 0 ...
-7 -6.5 0 -6 -5.5 0 -5 -4.5 0 -4 -3.5 0 -3 -2.5 0 -2 -1.5 0 -1 -.5 0 0 .5 0 1 1.5 0 2 2.5 0 3 3.5 0 4 4.5 0 ...
5 5.5 0 6 6.5 0 7 7.5 0];
kittyz = [6 6 6 5 5 4 4 3 3 2 2 1 1 0 0 -1 -1 -2 -2 -3 -3 -4 -4 -5 -5 -6 -6 -7 -7 -8 -8 -9 -9 -10 -10 -11 -11 -12 -12 -13 -13 ...
-14 -14 -15 -15 -16 -16 -17 -17 -18 -18 -19 -19 -20 -20 -21 -21 -22 -22 -23 -23 -24 -24 -25 -25 -26 -26 -27 -27 -28 -28 -29 -29 -30 -30 -29 -29 -28 -28 ...
-27 -27 -26 -26 -25 -25 -24 -24 -23 -23 -22 -22 -21 -21 -20 -20 -19 -19 -18 -18 -17 -17 -16 -16 -15 -15 -14 -14 -13 -13 -12 -12 -11 -11 -10 -10 ...
-9 -9 -8 -8 -7 -7 -6 -6 -5 -5 -4 -4 -3 -3 -2 -2 -1 -1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 6 -6 -6 -6 -5 -6 -4 -3 -6 ...
-2 -1 -6 0 1 -6 2 3 -6 4 5 -6 6 7 -6 8 7 -6 6 5 -6 4 3 -6 2 1 -6 0 -1 -6 -2 -3 -6 -4 -5 -6 ...
-6 -5 -6 -7 -8 -6 -9 -10 -6 -11 -12 -6 -13 -14 -6 -15 -16 -6 -17 -18 -6 -19 -20 -6 -20 -19 -6 -18 -17 -6 -16 -15 -6 -14 -13 -6 ...
-12 -11 -6 -10 -9 -6 -8 -7 -6];
figure(1)
axis([-200 200 -200 200 -200 200])
hold on
%plot3(kittyx,kittyy,kittyz);
%Rotation Part
object = [kittyx
kittyy
kittyz];
v=.2;
for t=0:.1:4*pi
x = -1*sin(t);
y = 1*cos(t);
pitch_angle = atan2(y,t)/sqrt((x/t)^2+(y/t)^2);
yaw_angle = atan2(y,t)/(x/t);
R = [cos(pitch_angle) 0 -sin(pitch_angle); 0 1 0; sin(pitch_angle) 0 cos(pitch_angle)];
R2 = [cos(yaw_angle) -sin(yaw_angle) 0; sin(yaw_angle) cos(yaw_angle) 0; 0 0 1];
object_pitched = R*(object);
object_yawed = R2*(object_pitched);
i = object_yawed(1,:);
j = object_yawed(2,:);
k = object_yawed(3,:);
view(45,45)
axis equal
%Plot and set axis
plot3(i,j,k)
axis([-200 200 -200 200 -200 200])
pause(0.2);
clf;
end
這正是我所期待的。非常感謝你! – Zared619