From: Matt Thomas on
Ben <benvoeveren(a)gmail.com> wrote in message <2069972631.29097.1279129690927.JavaMail.root(a)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
From: Matt J on
"Matt Thomas" <matt.at(a)gmail.com> wrote in message <i1kvlh$2sv$1(a)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)];
From: Charles McPherson on
Matt,
What you describe is a 2D rotation transformation which is normally performed by multiplying the (x,y) data points of the original coordinate system by a 2X2 rotation transformation matrix. Because it's a simple 2X2, the rotation can be easily expressed a a simple linear equation as well. This equation for a clockwize rotation by an angle, theta, is:

x_prime = x*cos(theta) + y*sin(theta);
y_prime = -x*sin(theta) + y*cos(theta);

where x_prime and y_prime are where the x,y moves to.

Usually, I do coordinate transformation using matrix algebra because it's clean and simple. Check out the Wiki at <http://en.wikipedia.org/wiki/Transformation_matrix#Rotation>


"Matt Thomas" <matt.at(a)gmail.com> wrote in message <i1krpq$iud$1(a)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
First  |  Prev  | 
Pages: 1 2
Prev: solve
Next: passing MATLAB structures to C/C++