Borrar filtros
Borrar filtros

Not able to rotate an object in matlab?

3 visualizaciones (últimos 30 días)
simar
simar el 14 de Feb. de 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 comentario
Sean de Wolski
Sean de Wolski el 14 de Feb. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Honglei Chen
Honglei Chen el 14 de Feb. de 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.

Más respuestas (0)

Categorías

Más información sobre Language Fundamentals en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by