rotation of 3D XYZ points by an ijk unit vector
43 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Andrew Dickins
am 6 Nov. 2024 um 13:07
Bearbeitet: Bruno Luong
am 7 Nov. 2024 um 10:00
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]
0 Kommentare
Akzeptierte Antwort
Bruno Luong
am 6 Nov. 2024 um 13:52
Bearbeitet: Bruno Luong
am 6 Nov. 2024 um 14:54
% 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_Rotates = R*XYZ % observe the first vector u after rotation becomes v
1 Kommentar
Bruno Luong
am 7 Nov. 2024 um 9:42
Bearbeitet: Bruno Luong
am 7 Nov. 2024 um 10:00
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_Rotates = R*XYZ % observe the first vector u after rotation becomes v
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Quaternion Math finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!