Not able to rotate an object in matlab?
3 views (last 30 days)
Show older comments
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 Comment
Sean de Wolski
on 14 Feb 2012
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.
Accepted Answer
Honglei Chen
on 14 Feb 2012
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 Comments
More Answers (0)
See Also
Categories
Find more on Language Fundamentals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!