rotation of 3D XYZ points by an ijk unit vector

9 Ansichten (letzte 30 Tage)
Andrew
Andrew am 6 Nov. 2024
Bearbeitet: Bruno Luong am 7 Nov. 2024
I have a XYZ co-ordinate points that I would like to rotate around the origin from one vector of a defined plane to another. For example I have a unit surface vector of a plane of [0.9997 -0.0240 -0.0053] and I would like to rotation my points so that this planes normal is parallel to the X axis [1 0 0].
How can I take my [X Y Z] co-ordinates and rotate them in 3 dimensions from vector [0.9997 -0.0240 -0.0053] to [1 0 0]

Akzeptierte Antwort

Bruno Luong
Bruno Luong am 6 Nov. 2024
Bearbeitet: Bruno Luong am 6 Nov. 2024
% source and target unit vectors
u = [0.9997; -0.0240; -0.0053] ; u = u/norm(u);
v = [1; 0; 0]; v = v/norm(v);
% Compute 3 x 3 rotation matrix R so that R*u is v
% see here foe ref of angle calculation
% https://www.mathworks.com/matlabcentral/answers/101590-how-can-i-determine-the-angle-between-two-vectors-in-matlab?s_tid=srchtitle
M = makehgtform("axisrotate",cross(u,v),2*atan(norm(u-v)/norm(u+v)));
R = M(1:3,1:3);
XYZ = [u, randn(3,6)], % (3 x n) your n data point coordinates
XYZ = 3×7
0.9997 0.6224 0.2960 1.1053 0.4341 0.6850 0.5836 -0.0240 -1.6776 -1.3716 -0.9371 1.1838 -0.0971 -0.5146 -0.0053 -1.1380 -1.2065 -0.3211 0.1301 -0.7294 -0.0976
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
XYZ_Rotates = R*XYZ % observe the first vector u after rotation becomes v
XYZ_Rotates = 3×7
1.0000 0.6685 0.3352 1.1291 0.4049 0.6910 0.5963 -0.0000 -1.6621 -1.3641 -0.9103 1.1939 -0.0806 -0.5004 -0.0000 -1.1346 -1.2049 -0.3151 0.1324 -0.7257 -0.0944
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
  1 Kommentar
Bruno Luong
Bruno Luong am 7 Nov. 2024
Bearbeitet: Bruno Luong am 7 Nov. 2024
Note that the choice here of axis rotation vector r := cross(u,v) is not unique; but it's the one that implies a smallest rotation angle.
Any unit vector that has the same distance to u and v can be setected as axis of rotation.
For example normalized (u+v)/2. The angle here is pi, the largest possible choice.
% source and target unit vectors
u = [0.9997; -0.0240; -0.0053] ; u = u/norm(u);
v = [1; 0; 0]; v = v/norm(v);
% Compute 3 x 3 rotation matrix R so that R*u is v
M = makehgtform("axisrotate",(u+v)/2,pi);
R = M(1:3,1:3);
XYZ = [u, randn(3,6)], % (3 x n) your n data point coordinates
XYZ = 3×7
0.9997 0.3643 -1.2357 0.2286 -0.0913 0.7236 -0.7353 -0.0240 0.3797 -1.1702 -0.3897 -1.1961 -0.6616 -0.5746 -0.0053 0.7244 0.2336 -0.6793 0.9005 1.2260 -1.4620
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
XYZ_Rotates = R*XYZ % observe the first vector u after rotation becomes v
XYZ_Rotates = 3×7
1.0000 0.3513 -1.2084 0.2415 -0.0674 0.7327 -0.7135 -0.0000 -0.3883 1.1996 0.3841 1.1980 0.6441 0.5920 0.0000 -0.7263 -0.2271 0.6781 -0.9001 -1.2298 1.4658
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by