Transformation matrix between two cartesian systems

조회 수: 54 (최근 30일)
Maciej Kupras
Maciej Kupras 2022년 10월 31일
댓글: Maciej Kupras 2022년 11월 1일
Hi,
I do have some points in 3D inertial frame of reference, that are randomly generated, but are meant to be measured with a sensor on a box. Let's say their coordinates are:
B=[x_inertial;y_inertial;z_inertial]
I also do have a vector that the sensor 'is looking' into the direction of. These is a unit vector made from randomly generated direction:
ro=2*pi*rand;
theta=2*pi*rand;
fi=2*pi*rand;
sensor_angles=[ro;theta;fi]; %this is the angle that sensor is looking at
sensor_direction=sensor_angles./norm(sensor_angles);%this is a unit vector that a sensor is looking at
I would like to have my inertial coordinates to have transformed into the reference frame of a sensor, but in a way that my new y_sesnor axis would be around zero (as the sensor is positioned on the Y axis of the box). I tried making transformation matrix:
C_F1_1=[cos(ro) -sin(ro) 0;sin(ro) cos(ro) 0;0 0 1];
C_F1_2=[cos(theta) 0 sin(theta);0 1 0; -sin(theta) 0 cos(theta)];
C_F1_3=[1 0 0 ;0 cos(fi) -sin(fi);0 sin(fi) cos(fi)];
C_F1=C_F1_1*C_F1_2*C_F1_3; %final transformation matrix
And then the multiplying. And as I understand, the A matrix should me coordinates in a referance frame of a sensor.
A=C_F1*B;
However, the new matrix is nowhere near the zero at Y (and any) axis.
For an example, for the 10 randomly generated points I get the matrix of randomly generated points on a sphere with a radius=1:
B =
Columns 1 through 9
0.3246 -0.6403 0.5266 -0.0176 0.4037 -0.0428 0.7374 0.7950 -0.6923
0.8497 -0.5035 -0.8488 0.0264 0.8840 0.5389 0.2422 -0.5109 0.3030
0.4154 0.5801 -0.0476 -0.9995 -0.2358 0.8413 0.6306 0.3271 -0.6549
Column 10
0.1225
-0.0318
-0.9920
Sensor angles:
sensor_angles =
1.8237 %ro
5.5713 %theta
1.3197 %fi
Transformation matrix:
C_F1 =
-0.1894 -0.0823 0.9784
0.7331 -0.6748 0.0852
0.6533 0.7334 0.1881
The final A matrix:
Columns 1 through 9
0.2750 0.7303 -0.0765 -0.9768 -0.3799 0.7869 0.4574 0.2115 -0.5345
-0.3001 -0.0802 0.9548 -0.1158 -0.3207 -0.3235 0.4308 0.9554 -0.7678
0.9134 -0.6784 -0.2874 -0.1802 0.8677 0.5255 0.7780 0.2062 -0.3533
Column 10
-0.9912
0.0268
-0.1299
Then, I check which points from the A matrix are "visible" (follow up to my previous question: https://www.mathworks.com/matlabcentral/answers/1839323-angle-between-two-3d-vectors) for the sensor (that has POV of a circle of 10 degrees to the each side). It turns out that the sensor sees:
A_fov =
0.2115
0.9554
0.2062
And as you can see, A_fov is nowewhere near close the sensor_direction:
sensor_direction =
0.3035
0.9272
0.2196
How can I solve the problem?
  댓글 수: 11
Jim Riggs
Jim Riggs 2022년 11월 1일
The plane perpendicular to the Y axis is the X-Z plane. Any point with a -Y value will be behind the camera, and any point with a +Y value is in front of the camera. The camera probably has a limited field of view, so you would need to calculate the angle from the camera boresight to each point to tell whether it is visible to the camera.
for each point P[x; y; z], the angle off boresight (i.e. the Y-axis) is
acos(dot([0,1,0], P./norm(P)) % angle from the Y-axis, (radians)
Maciej Kupras
Maciej Kupras 2022년 11월 1일
Right, I understand. Thank you very much for the huge help.

댓글을 달려면 로그인하십시오.

채택된 답변

Jim Riggs
Jim Riggs 2022년 10월 31일
편집: Jim Riggs 2022년 10월 31일
Coordinate rotation (or transformation) involves expressing the coordinates of a point defined in one reference frame in terms of another frame. Coordinate frame rotations may be conducted in one of two “directions”. The conventions used to describe the rotation directions are “direct” and “inverse”. These conventions are linked to the definition of the rotation displacement angle(s).
Consider the Z-axis rotation depicted in the figure. The figure illustrates two sets of axes, one in blue (with axes X, Y, and Z) and one in red (with axes X’, Y’, and Z’). From the perspective of the figure, the red frame is displaced relative to the blue frame. This is implied by the sense of the angle psi . The figure indicates that the angle psi is measured from the blue to the red, and is a positive rotation about the Z axis using the right-hand rule. By definition, the coordinates of a vector in the displaced (red) frame may be transformed to the fixed (blue) frame using the direct transformation. The opposite transform is the inverse transformation. The inverse transformation will transform the coordinates of a point in the fixed (blue) frame to the displaced (red) frame. Note that the fixed (blue) frame is considered as our point of reference, or frame of observation, and it is the fixed frame which is used to define the sign of the angle, psi. Now, suppose that we take a point of observation in the red frame. With our point of observation in the red frame, we treat the red frame as the fixed frame, and observe that the blue frame has been displaced from the red frame through angle -psi. The displacement angle, psi, is now defined relative to the Z’ (red) axis, is a negative rotation in the figure. From this perspective, if we wish to transform the coordinates of a point from the blue frame to the red frame, this would now be a direct transformation (a transformation from the displaced frame to the fixed frame is a direct transformation), and the value for psi, as defined in the red frame, is now a negative rotation angle.
To summarize,
  • When describing the relationship between two reference frames, one must be used as the fixed reference (frame of observation) to describe the displacement of the other. The choice may be arbitrary, but the fixed reference defines the sign convention for the angle rotations.
  • The direct transformation transforms the coordinate of a point from the displaced frame to the fixed frame.
  • The inverse transformation transforms the coordinates of a point from the fixed frame to the displaced frame.
  • The direct transformation through angle psi, is equivalent to the inverse transformation through angle -psi, and vice versa.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Motion Modeling and Coordinate Systems에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by