Rotate a Cartesian vector into an arbitrary orthogonal basis

19 views (last 30 days)
Given an arbitrary point in an 3D space, I want to take a "step" and find the new point. Although this is simple vector addition, the direction of the step should be determined by previous steps. I need to rotate the determine the rotation matrix to turn the simple Cartesian basis into an arbitrary orthogonal basis given just two vectors. So, given three points P0, P1, and P2, and the associated vectors A (P0 to P1) and B (P1 to P2), I would like to step to P3, whereby a step e.g. (0.3,0.5,0.7) in the Cartesian system is rotated to an orthogonal system in which P0, P1, P2, and P3 all lie in the same plane.
Let's say you have an arbitrary vector A:
A = [0.61, 1.54, -0.60] ;
If we set A to be our new "x-axis", then one way of determing the rotation matrix would be:
modX = sqrt(0.61^2 + 1.54^2 + (-0.6)^2) ;
rotM = vrrotvec2mat(vrrotvec([modA, 0, 0],A)) ;
Probably not the best way, but it should work. Anyway, if we bring in another vector B:
B = [0.78, -0.83, 0.81] ;
We can determine a "z-axis" using the cross product:
AxB = cross(A,B) = [0.7494, -0.9621, -1.7075] ;
By extension of the one-vector case, we can determine the rotation matrix using:
modZ = sqrt(0.7494^2 + (-0.9621)^2 + (-1.7075)^2) ;
rotM = vrrotvec2mat(vrrotvec([modA, 0, modZ],(A + AxB)) ;
However, this doesn't seem to work. That is, it produces a rotation matrix, but it doesn't produce the results I'm expecting.
After a search through other answers, I found the function absor.m. Using the same example vectors, I believe the correct usage would be:
[rotation_struct,~,~] = absor([0, 0, 0; modX, 0, modZ]', [0, 0, 0; (A + AxB)]') ;
This produces a different rotation matrix, which certainly implies that my own method is flawed. However, the absor.m matrix still does not produce the results I'm looking for.

Accepted Answer

Matt J
Matt J on 21 Aug 2020
Edited: Matt J on 21 Aug 2020
I can't fully understand your post, but if you are simply trying to build a set of right-handed orthogonal x,y,z axes satisfying,
(1) the x-axis coincides with A
(2) the x,y plane is spanned by A and B,
then it would be as follows:
xaxis=A(:)/norm(A);
zaxis=cross(xaxis,B(:)/norm(B));
yaxis=cross(zaxis,xaxis);
rotM=[xaxis,yaxis,zaxis].'
  3 Comments
Matt J
Matt J on 21 Aug 2020
Edited: Matt J on 21 Aug 2020
If we have a default vector V, would rotM*V rotate V to be in the new orthogonal basis?
Yes, it will.
Also, shouldn't your answer read:
Yes, I fixed it.
Paul Gratrex
Paul Gratrex on 24 Aug 2020
Thanks, this works! One change should be made: your code assumes that A and B are already orthogonal, which was not the case. Thus, the code needs to be modified, vis:
Given vectors A and B, wherein A coincides with our new x-axis and A and B are two non-orthogonal vectors that both lie purely in the X-Y plane, then the rotation matrix is found by:
x_axis = A(:)/norm(A) ;
z_axis = cross(x_axis,B(:)/norm(B)) ;
y_axis = cross(z_axis,x_axis) ;
rotM = [x_axis,y_axis/norm(y_axis),z_axis/norm(y_axis)] ;
Thanks a bunch!

Sign in to comment.

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!