필터 지우기
필터 지우기

Not able to rotate an object in matlab?

조회 수: 4 (최근 30일)
simar
simar 2012년 2월 14일
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