Rotating a coordinate with a rotation matrix

46 views (last 30 days)
So I'm working with a rotation matrix, basically trying to simulate
Where and are coordinates. H is a transformation matrix such as rotation
rot = [cosd(5),sind(5);-sind(5),cosd(5)];
Now, according to the equation, multiplying the transformation matrix with a coordinate would result in a coordinate but if is [9,1] for example, if i multiply with the rotation matrix.
test_coor = [9;1];
h = [cosd(5),sind(5);-sind(5),cosd(5)];
out = test_coor * h;
I would get:
out =
9.0529
0.2118
But it's in decimals. So do i have to round it up the values after? Or am i supposed to do something with it to get ?
  3 Comments
Stewart Tan
Stewart Tan on 10 Sep 2019
@Bruno Luong because the equation is saying, the transformation applied to would become . I have with me, say [9,0] hence the equation would allow me to check if after being rotated would be equal to [9,0] for example. Hence i wonder if the decimals should be kept.
Bruno Luong
Bruno Luong on 10 Sep 2019
Edited: Bruno Luong on 10 Sep 2019
So you want to find out the (xi,yi) such that
H*[xi,yi] = [9;1] % 1 or 0, make your own mind
?
In that case
H = [cosd(5),sind(5);-sind(5),cosd(5)];
xy_j = [9;1];
xy_i = H'xy_j
you can then check
H*xy_i

Sign in to comment.

Accepted Answer

Jim Riggs
Jim Riggs on 10 Sep 2019
Edited: Jim Riggs on 10 Sep 2019
There seems to be some confusion regarding what the coordinate rotation transform is doing.
One way to think about it is that it expresses the coordinates of a point given in one reference frame in terms of some other frame. For a pure rotation, the frames are co-located, i.e. the point [0,0] is the same point in both frames.
Consider the point (in blue) in the figure, below. I have superimposed two different, co-located reference frames in the figure, one in black with the i subscript, and another one in red with a j subscript. The "j" frame is shown rotated through a positive angle "a" relative to the "i" frame.
You can think of the point as existing on it's own, appart from any reference frame. Then when we impose a reference frame, we can now describe the position of that point in that frame. Changing from the black frame to the red frame does not changethe position of the blue point, it only changes the way I observe it.
In the above figure, the coordinates of the point in the "i" frame (on the black grid) are [4; 2]. The figure implies a rotation of +13.6441 degrees, such that the coordinates of the point in the "j" frame (on the red grid) are [4.3589, 1.0000].
The rotation of a point in the i frame, expressed in the j frame is computed by
h = [cosd(a), sind(a) ; -sind(a), cosd(a)]
[ xj ; yj ] = h * [ xi ; yi ]
so, for [ xi; yi ] = [ 4; 2 ] (or [ 4.0000; 2.0000 ] ) and a = +13.6441 degrees,
[ xj; yj ] = [4.3589, 1.0000]
We are simply describing the point using 2 different sets of axes, which are related by the angle a.
Bellow is an illustration of your values;
[ xi, yi ] = [ 9; 1 ] and a = 5 degrees.
From the figure you can see that in the j frame, the point is just a bit more than 9, and a little above zero.
Matlab Answers 20190910a.JPG
  5 Comments
Stewart Tan
Stewart Tan on 12 Sep 2019
@Jim Riggs thank you so much! Very clear explanation. Cheers!
Bruno Luong
Bruno Luong on 12 Sep 2019
Edited: Bruno Luong on 12 Sep 2019
Remarks: no need to divide by denominator
a = atan2(xi*yj - yi*xj, xi*xj + yi*yj)
This 2D formula is the "z-oriented version" (counter-clockwise convention) given many time in 3D for angle between two 3D vectors v1 and v2:
atan2(norm(cross(v1,v2)), dot(v1,v2))
in 2D it's also given here

Sign in to comment.

More Answers (1)

Timothy Simon Thomas
Timothy Simon Thomas on 30 May 2020
Edited: Timothy Simon Thomas on 30 May 2020
Rotation Matrix acting on a Vector
Parameters
Theta holds the angle to be rotated by, vector is the initial vector.
vector=[1;6]
theta=270;
Plot Initial Vector
plot([0 vector(1)],[0 vector(2)],'r--^','LineWidth',2);
title("Vector Rotation","BackgroundColor",'y')
hold on;
Rotation Matrix
2D-rotation matrix on the X-Y plane.
Rot_by_theta=[cosd(theta) -sind(theta) ; sind(theta) cosd(theta)]
Rotate
Multiply the initial vector with the rotation matrix to get the rotated vector.
rotated_vector=(Rot_by_theta*vector);
Plot Rotated Vector
Insert 0 at the begining to visualize the vector
plot([0 rotated_vector(1)],[0 rotated_vector(2)],'m-o','LineWidth',2);
legend("Ini_vector","Rotated")
Aesthetics
Draws X-Y axes, sets limts between -10 and 10 on both axes
grid on
xlim([-10 10])
ylim([-10 10])
line([xlim],[0 0]);
line([0 0],[ylim]);
hold off

Community Treasure Hunt

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

Start Hunting!