Not able to rotate an object in matlab?

4 次查看(过去 30 天)
hello there, I'm working on rotation matrices and want to rotate a spiral along some axis (any axis will do my job). I have written the following code for that, however its stretching and squeezing the spring and rotating arbitrarily. Please help
clear all
%close all
t = -5*pi:0.1:5*pi;
z = t
x = cos(t)
y = sin(t)
M = [x;y;z]
plot3(M(1,:),M(2,:),M(3,:),'LineWidth',1.5)
xlim([-3 3])
ylim([-3 3])
grid on
hold on;
H = line ([-3 3],[0 0])
set (H,'color','r','LineWidth',1)
H = line ([0 0],[-3 3])
set (H,'color','r','LineWidth',1)
H = line ([0 0],[0 0],[-20 20])
set (H,'color','r','LineWidth',1)
a = pi/2;
T = [ 1 0 0; 0 cos(a) -sin(a); 0 sin(a) cos(a)]
%T = [ 0.7071 0 -0.7071; 0 1 0; 0.7071 0 0.7071]
hold on;
S = T*M
plot3(S(1,:),S(2,:),S(3,:),'m')
xlabel ('x')
ylabel ('y')
zlabel ('z')
  1 个评论
Sean de Wolski
Sean de Wolski 2012-2-14
Can you please clarify your question? What is it doing that you do/don't expect? What specifically do you want us to help you with? etc.

请先登录,再进行评论。

采纳的回答

Honglei Chen
Honglei Chen 2012-2-14
Hi Simar,
I think your program is doing what you want it to do, it rotates the whole thing 90 degrees in respect to the x axis. You probably don't see it because you are limiting your axis to [-3 3] in both x and y direction. Remove the xlim and ylim in your code and you will see the result in scale.
Of course, if you want to rotate it according to an arbitrary axis, then there are more to do to build the rotation matrix.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Language Fundamentals 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by