Filter löschen
Filter löschen

Not able to rotate an object in matlab?

4 Ansichten (letzte 30 Tage)
simar
simar am 14 Feb. 2012
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 Kommentar
Sean de Wolski
Sean de Wolski am 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Honglei Chen
Honglei Chen am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Language Fundamentals finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by