Rotating a coordinate with a rotation matrix

42 visualizzazioni (ultimi 30 giorni)
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 Commenti
Stewart Tan
Stewart Tan il 10 Set 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 il 10 Set 2019
Modificato: Bruno Luong il 10 Set 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

Accedi per commentare.

Risposta accettata

Jim Riggs
Jim Riggs il 10 Set 2019
Modificato: Jim Riggs il 10 Set 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 Commenti
Stewart Tan
Stewart Tan il 12 Set 2019
@Jim Riggs thank you so much! Very clear explanation. Cheers!
Bruno Luong
Bruno Luong il 12 Set 2019
Modificato: Bruno Luong il 12 Set 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

Accedi per commentare.

Più risposte (1)

Timothy Simon Thomas
Timothy Simon Thomas il 30 Mag 2020
Modificato: Timothy Simon Thomas il 30 Mag 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

Categorie

Scopri di più su 3-D Scene Control in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by