Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Incorrect rotation calculations

Subject: Incorrect rotation calculations

From: Eugene

Date: 17 Jan, 2013 04:47:11

Message: 1 of 3

Hi!
I'm novice in MatLAB. I need simple 3D rotation around X axis. I know there are a lot of 3D libs/apps, but I need my own calculations.
I'm trying to do this:

% rotation angle
a = degtorad(45.0);
%rotation matrix (around X axis)
MX = [1.0 0.0 0.0;
      0.0 cos(a) -sin(a);
      0.0 sin(a) cos(a)];
%source point coords
x = 0.5
y = 0.5
z = 0.7071

% plot source point
plot3(x,y,z,':go');grid on;
hold on;
%plot radius-vector to source pt
line([0 x],[0 y],[0 z],'color','g');

% rotation
new_pt = MX * [x; y; z]

% plot destination point
x = new_pt(1,1); y = new_pt(2,1); z = new_pt(3,1);
plot3(x, y, z,':ro');
%plot radius-vector to destination pt
line([0 x],[0 y],[0 z],'color','r');

I have source point [0.5 0.5 0.7071], after rotation- [0.5 -0.1464 0.8535]
But it is incorrect answer!
It seems to me y value can't be negative and z also has invalid value.
What's wrong in my solution?
P.S. I'm sorry for my rude English

Subject: Incorrect rotation calculations

From: Roger Stafford

Date: 17 Jan, 2013 06:34:11

Message: 2 of 3

"Eugene" wrote in message <kd7vof$gcu$1@newscl01ah.mathworks.com>...
> % rotation angle
> a = degtorad(45.0);
> %rotation matrix (around X axis)
> MX = [1.0 0.0 0.0;
> 0.0 cos(a) -sin(a);
> 0.0 sin(a) cos(a)];
> %source point coords
> x = 0.5
> y = 0.5
> z = 0.7071
>
> % plot source point
> plot3(x,y,z,':go');grid on;
> hold on;
> %plot radius-vector to source pt
> line([0 x],[0 y],[0 z],'color','g');
>
> % rotation
> new_pt = MX * [x; y; z]
>
> % plot destination point
> x = new_pt(1,1); y = new_pt(2,1); z = new_pt(3,1);
> plot3(x, y, z,':ro');
> %plot radius-vector to destination pt
> line([0 x],[0 y],[0 z],'color','r');
>
> I have source point [0.5 0.5 0.7071], after rotation- [0.5 -0.1464 0.8535]
> But it is incorrect answer!
> It seems to me y value can't be negative and z also has invalid value.
> What's wrong in my solution?
- - - - - - - - -
  That rotation looks valid to me. You have rotated the point counterclockwise from the y-axis toward the z-axis by 45 degrees. The point (.5,.5,.7071) should end up at (.5,-.1464,.8535) just where you have it. Why don't you think that is right? The original point was more than 45 degrees from the y-axis, so after 45 degrees more it would rotate past the z-axis and produce a negative y. Were you expecting a rotation in the opposite direction? If so, your MX would be incorrect.

Roger Stafford

Subject: Incorrect rotation calculations

From: Eugene

Date: 18 Jan, 2013 01:02:08

Message: 3 of 3

> - - - - - - - - -
> That rotation looks valid to me. You have rotated the point counterclockwise from the y-axis toward the z-axis by 45 degrees. The point (.5,.5,.7071) should end up at (.5,-.1464,.8535) just where you have it. Why don't you think that is right? The original point was more than 45 degrees from the y-axis, so after 45 degrees more it would rotate past the z-axis and produce a negative y. Were you expecting a rotation in the opposite direction? If so, your MX would be incorrect.
>
> Roger Stafford

Yes, this rotation correct. My source point was incorrect- it must be [0.5 0.5 0.5], after rotation it must be [0.5 0.0 0.7071].
Thank you for your answer!

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us