Rotating a coordinate with a rotation matrix
23 ビュー (過去 30 日間)
古いコメントを表示
So I'm working with a rotation matrix, basically trying to simulate
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237771/image.png)
Where
and
are coordinates. H is a transformation matrix such as rotation
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237772/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237773/image.png)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237774/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237775/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237776/image.png)
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
?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237775/image.png)
3 件のコメント
Bruno Luong
2019 年 9 月 10 日
編集済み: Bruno Luong
2019 年 9 月 10 日
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
採用された回答
Jim Riggs
2019 年 9 月 10 日
編集済み: Jim Riggs
2019 年 9 月 10 日
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237805/image.jpeg)
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237835/image.jpeg)
5 件のコメント
Bruno Luong
2019 年 9 月 12 日
編集済み: Bruno Luong
2019 年 9 月 12 日
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
その他の回答 (1 件)
Timothy Simon Thomas
2020 年 5 月 30 日
編集済み: Timothy Simon Thomas
2020 年 5 月 30 日
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で 3-D Scene Control についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!