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:
Matrix Rotation About Origin

Subject: Matrix Rotation About Origin

From: Matt Thomas

Date: 14 Jul, 2010 17:23:06

Message: 1 of 7

Hi All -

I have a matrix that I need to rotate a specified number of degrees about the x,y origin. I have found resources for matrix rotation for 90 degrees but I need a way to do it a user specified amount (say, for example, 5 degrees).

Can anyone point me in the right direction?

Thanks!

matt

Subject: Matrix Rotation About Origin

From: Matt J

Date: 14 Jul, 2010 17:34:05

Message: 2 of 7

"Matt Thomas" <matt.at@gmail.com> wrote in message <i1krpq$iuc$1@fred.mathworks.com>...
> Hi All -
>
> I have a matrix that I need to rotate a specified number of degrees about the x,y origin. I have found resources for matrix rotation for 90 degrees but I need a way to do it a user specified amount (say, for example, 5 degrees).
======

If you have the Image Processing Toolbox, you can use imrotate(). Otherwise, you might have to fall back to interp2().

Subject: Matrix Rotation About Origin

From: Andy

Date: 14 Jul, 2010 17:45:23

Message: 3 of 7

"Matt Thomas" <matt.at@gmail.com> wrote in message <i1krpq$iuc$1@fred.mathworks.com>...
> Hi All -
>
> I have a matrix that I need to rotate a specified number of degrees about the x,y origin. I have found resources for matrix rotation for 90 degrees but I need a way to do it a user specified amount (say, for example, 5 degrees).
>
> Can anyone point me in the right direction?
>
> Thanks!
>
> matt

It sounds like you found rot90? FYI, I do not think it means what you think it means.

Subject: Matrix Rotation About Origin

From: Ben

Date: 14 Jul, 2010 17:47:40

Message: 4 of 7

function [m] = rotmat(a,b,c);
%calculates the rotation matrix in order XYZ in a right handed system
%the coordinate system is rotated, not the points!

ca=cos(a);
sa=sin(a);
cb=cos(b);
sb=sin(b);
cc=cos(c);
sc=sin(c);
m1=[1 0 0;0 ca -sa;0 sa ca];%rotation only about x axis
m2=[cb 0 sb;0 1 0;-sb 0 cb];%rotation only about y axis
m3=[cc -sc 0;sc cc 0;0 0 1];%rotation only about z axis
% m1=[1 0 0;0 ca sa;0 -sa ca];
% m2=[cb 0 -sb;0 1 0;sb 0 cb];
% m3=[cc sc 0;-sc cc 0;0 0 1];
m=m1*m2*m3;


succes

Subject: Matrix Rotation About Origin

From: Ravi

Date: 14 Jul, 2010 18:28:20

Message: 5 of 7

Hi Matt,

If your matrix is a 1-D column vector, the problem is of coordinate transformation.

If your matrix is a 2D matrix that represents a tensor (such as stress, moment of inertia), the problem is of tensor transformation.

Let it be desired to transform from base to target coordinate system.

Let T= nxn orthogonal transformation matrix from base to target coordinate system (explained below)

1-D column vector:
X0= nx1 column vector in base coordinate system
X = nx1 column vector in target coordinate system

Then X=T*X0

2-D tensor matrix :
K0= nxn tensor matrix in base coordinate system
K = nxn tensor matrix in target coordinate system

Then K=T*K0*T' where T' is the transpose of T

Transformation Matrix T:
Transformation Matrix T is problem-dependent orthogonal matrix (inverse of T=transpose of T).
The rows of T are the direction cosines of the axis of the target coordinate system with respect to the base coordinate system.

For example, if it is desired to rotate about the Z-axis of the base coordinate system,

T=[
cos(angle) sin(angle) 0
cos(angle+pi/2) sin(angle+pi/2) 0
0 0 1 ]

where angle=rotation angle

If you need to rotate about X or Y-axis, modify T appropriately.

Hope this helps !

Ravi


"Matt Thomas" <matt.at@gmail.com> wrote in message <i1krpq$iuc$1@fred.mathworks.com>...
> Hi All -
>
> I have a matrix that I need to rotate a specified number of degrees about the x,y origin. I have found resources for matrix rotation for 90 degrees but I need a way to do it a user specified amount (say, for example, 5 degrees).
>
> Can anyone point me in the right direction?
>
> Thanks!
>
> matt

Subject: Matrix Rotation About Origin

From: Matt Thomas

Date: 14 Jul, 2010 18:29:05

Message: 6 of 7

Ben <benvoeveren@gmail.com> wrote in message <2069972631.29097.1279129690927.JavaMail.root@gallium.mathforum.org>...
> function [m] = rotmat(a,b,c);
> %calculates the rotation matrix in order XYZ in a right handed system
> %the coordinate system is rotated, not the points!
>
> ca=cos(a);
> sa=sin(a);
> cb=cos(b);
> sb=sin(b);
> cc=cos(c);
> sc=sin(c);
> m1=[1 0 0;0 ca -sa;0 sa ca];%rotation only about x axis
> m2=[cb 0 sb;0 1 0;-sb 0 cb];%rotation only about y axis
> m3=[cc -sc 0;sc cc 0;0 0 1];%rotation only about z axis
> % m1=[1 0 0;0 ca sa;0 -sa ca];
> % m2=[cb 0 -sb;0 1 0;sb 0 cb];
> % m3=[cc sc 0;-sc cc 0;0 0 1];
> m=m1*m2*m3;
>
>

Thank you for the replies. I was in fact, looking at the rot90 command - I think now it designed for rotating images not matrices.

In response to the code posted above, I need the program to change the values of my x,y,z points, not the coordinate system. This is because I will be doing more translation of these points later on.

Is there no command for rotating a set of x,y points defined in a 2 column matrix about the origin of the x,y coordinate system?

-matt

Subject: Matrix Rotation About Origin

From: Matt J

Date: 14 Jul, 2010 19:43:04

Message: 7 of 7

"Matt Thomas" <matt.at@gmail.com> wrote in message <i1kvlh$2sv$1@fred.mathworks.com>...

> In response to the code posted above, I need the program to change the values of my x,y,z points, not the coordinate system.
===============

The two sound the same to me.

> Is there no command for rotating a set of x,y points defined in a 2 column matrix about the origin of the x,y coordinate system?
========

Create a rotation matrix, similar to what has been described to you (or see below).You can multiply the 2 column matrix with the rotation matrix.


function R=R2d(x)
%2D Rotation matrix counter-clockwise.
%
%R=R2d(deg)
%
%Input is in degrees.
%
%See also Rx,Ry,Rz,,R3d,M2d,M3d

R= [cosd(x),-sind(x); sind(x),cosd(x)];

Tags for 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