i have 3 axis starting at a point of origin and a rotated vector dir1_new starting at the origin. How can i calculate the rotation matrix =
E.G
orig = [311.51 -23.0379 -448.7862]
axis_1 = [2.7239 -0.2014 -3.9228] % starts at origin
axis_2 = [-0.4315 -5.8348 9.9199e-06] % starts at origin
axis_3 = [4.4008 -0.3255 3.0715] % starts at origin
my new vector is :
dir1_new = [2.6843 -0.1997 -3.9435] % starts at origin

6 commentaires

Jim Riggs
Jim Riggs le 7 Jan 2020
Modifié(e) : Jim Riggs le 7 Jan 2020
This question does not contain enough information.
It appears that the 3 axis_n vectors define an orthogonal set, and you specify a direction vector dir1_new, assumed to be in this set of axes.
but the question is not clear. It seems that dir1_new is the final direction vector after some rotation, but we need to know where it started from, i.e. what is the starting direction?
(Note that the actual position of the origin is not important since the axis and direction vectors as given appear to be relative vectors)
James Tursa
James Tursa le 7 Jan 2020
And, if you only have one rotated vector then there will be infinitely many rotation matrices that will work.
bbah
bbah le 8 Jan 2020
The 3 vectors define an orthogonal set and the dir1_new vector is the new vector of axis_1 in a new step. Now i want the angles of the new vector in the axis_1 - axis_2 plane, axis_1-axis_3 plane and axis_2-axis_3 plane. They all start at the origin but like mentioned above it should not be important.
Jim Riggs
Jim Riggs le 8 Jan 2020
Need one last point of clarification before an answer may be proposed.
If I interpret the three axes (axis_1, axis_2, and axis_3) to be (X, Y, and Z), then we have a left-handed coordinate frame. Note that if I construct unit vectors from the axis vectors:
Vmag = @(x) sqrt(sum(x.^2)):
U1 = axis_1./Vmag(axis_1);
U2 = axis_2./Vmag(axis_2);
U3 = axis_3/Vmag(axis_3);
Now U1 x U2 = -U3
U2 x U3 = -U1, and
U3 x U1 = -U2
A couple suggested ways to turn this into a propper right-handed system:
1) swap the 1 and 2 axes, or
2) negate axis 3
bbah
bbah le 8 Jan 2020
The three vectors are already unit vectors. Should i just negate axis 3 ? And how to calculate then the rotations ?thank you
Jim Riggs
Jim Riggs le 8 Jan 2020
No, these are not unit vectors. Their magnitudes are all greater than 1.

Connectez-vous pour commenter.

 Réponse acceptée

Jim Riggs
Jim Riggs le 8 Jan 2020
Modifié(e) : Jim Riggs le 8 Jan 2020

1 vote

I'll assume that we make the reference frame right-handed by negating the axis_3 vector such that
axis_1 = [2.7239 -0.2014 -3.9228];
axis_2 = [-0.4315 -5.8348 9.9199e-6];
axis_3 = [-4.4008 0.3255 -3.0715];
% Now vector r is rotated from axis_1 to
dir1 = [2.6843 -0.1997 -3.9435]
In the above vectors, I have flipped the sign on axis_3, but kept dir1 the same.
I can't tell if it is also appropriate to flip the sign on the Z-component for dir1, i.e.
dir1 = [2.6843 -0.1997 3.9435];
You will have to decide if this makes sense based on your problem and this is what you realy want.
Now I want to describe the dir1 vector in the user-specified coordinate frame defined by axis_1, axis_2, and axis_3.
I will construct unit vectors for each axis (as in my comment above):
Vmag = @(x) sqrt(sum(x.^2)));
U1 = axis_1./Vmag(axis_1);
U2 = axis_2./Vmag(axis_2);
U3 = axis_3./Vmag(axis_3);
Now project vector dir1 onto the user axes. I call this projected vector r:
r = [dot(dir1,U1) dot(dir1,U2) dot(dir1,U3)];
Vector r is vector dir1 expressed in the user-defined axes (axis_1, axis_2, axis_3).
I also want a unitized vector for the direction:
Ur = r./Vmag(r);
Now Ur is the unit vector in the "r" direction, expressed in the user reference frame, such that r(1) {and Ur(1)} is along axis_1, r(2) { and Ur(2)} is along axis_2, and r(3) { and Ur(3)} is along axis_3.
Now, my understanding of your original question is that this unit vector, Ur, represents a rotation from U1, so you want to know how to find the rotation matrix that will transform U1 to Ur, i.e you want matrix C such that [C] U1 = Ur
However, in your most recent comment, you say you want the angles based on projections in the three planes of the reference frame. So these are not the same thing.
However, once you have Ur, you have the vector projetions of dir1 along all 3 of the user-defined axes, so it is easy to compute angles in this frame from these components. Again, you will need to be more clear on what it is that you are wanting.

14 commentaires

Jim Riggs
Jim Riggs le 8 Jan 2020
Modifié(e) : Jim Riggs le 8 Jan 2020
One way to calculate the angles is as follows (Note that we are measuring the displacement of vector r from the X-axis, i.e. "axis_1"):
Matlab Answers 20200108.JPG
This can be represented as a direction cosine matrix using a Yaw-Pitch rotation sequence;
Note also that the effect of changing the sign on dir1(3) causes the vector r to point down (rather than up) in the figure, above, and this changes the sign on theta. The yaw angle, Psi, is unaffected.
bbah
bbah le 9 Jan 2020
So basically if i want the angles of my vector dir to every direction i need to calculate three psi for every axis ? E.G
PS1 = atan2d(ry,rx) PS2 = atan2d(rz,rx) PS3 = atan2d(ry,rz)
Jim Riggs
Jim Riggs le 9 Jan 2020
If you want the angle based on the vector projection in each of these planes, then that seems correct.
It is a good idea to draw a picture to make sure that you get the signs right.
Jim Riggs
Jim Riggs le 9 Jan 2020
Modifié(e) : Jim Riggs le 9 Jan 2020
One more comment:
PS1 = atan2(ry,rx) is an angle rotation about the Z-axis.
PS2 = atan2(rz, rx) is an angle rotation about the Y-axis.
PS3 = atan2(ry, rz) is an angle rotation about the X-axis.
This numeric notation might lead to confusion.
bbah
bbah le 9 Jan 2020
Yes i got that. Thank you a lot
what if my axis are
axis_1 = [0.611 -0.00 -0.7916]
axis_2 = [-0.7916 -0.00 -0.611]
axis_3 = [-0.00 1.000 0.000]
dir1 = [-0.6779 0.0054 -0.7352]
my three angles are 80.3467, 1.8467 and 89.6858 but these doesnt make sense or do they ?
Jim Riggs
Jim Riggs le 10 Jan 2020
Modifié(e) : Jim Riggs le 10 Jan 2020
As I said before, I don't know what these vectors represent, so I can't comment on whether the calculation is the correct one for the problem or not. If what you want is to calculate the angle of the vector projection in each of the primary planes, then you should draw a sketch, like this one, to help determine what parameter you want.
This drawing is looking down the Y-axis (Y-axis coming out of the screen)
You can calculate the angle to the x-axis (angle a) or the angle to the z-axis (angle b).
You must decide which one is right based on your problem.
angle a = atan2(-rz, rx)
angle b = atan2(rx, rz)
Note that since we are looking down the Y-axis, angle a represents a negative rotation about Y (from X-axis to r) , and angle b represents a positive rotation about Y (from Z-axis to r), thus the minus sign in the angle a term. It is not necessary to define the signs this way, but you must keep track of the angles and what they represent, so in my opinion this is helpful.
bbah
bbah le 10 Jan 2020
Okay i got it. You are describing it perfectly. Thanks a lot.
What i dont understand is the dot product u did to express the vector dir1 in user defined axes. Why are you using a scalar product ?
Jim Riggs
Jim Riggs le 10 Jan 2020
Modifié(e) : Jim Riggs le 10 Jan 2020
You start with the understanding that the direction vector dir1 and the three axes vectors are defined in some common coordinate system.
Next, I am projecting vector dir1 onto each of the three user defined axes. This is a way of describing vector dir1 in the new reference frame.
dir1 is the direction vector and U1 is a unit vector in the direction of axis 1, so the scalar value "dir1 dot U1" is the projection of dir1 onto axis 1. Then you do the same for axis 2 and axis 3. These three scalar values make up the components of a vector I called r, which is vector dir1 expressed in this new axis system.
bbah
bbah le 10 Jan 2020
But isnt my dir1 already in my coordinate system ?
Jim Riggs
Jim Riggs le 10 Jan 2020
The way that you originally specified the problem, I assumed that dir1 was in the same coordinate system used to define axis_1, axis_2, and axis_3. I don't realy know for a fact that this is true, it was an assumption on my part. I do not know where dir1 came from, so I don't know how it is defined.
bbah
bbah le 10 Jan 2020
If dir1 is defined in my coordinate system with normalized vectors axis_1 axis_2 and axis_3 do i need to produce vector r ?
Jim Riggs
Jim Riggs le 10 Jan 2020
Modifié(e) : Jim Riggs le 10 Jan 2020
No.
Vector r represents the transformation of dir1 into the user coordinate frame. If dir1 is already defined in this frame, then you do not need to transform it.
bbah
bbah le 10 Jan 2020
Got it. Thank you a lot

Connectez-vous pour commenter.

Plus de réponses (1)

Matt J
Matt J le 10 Jan 2020
Modifié(e) : Matt J le 10 Jan 2020

0 votes

B1=[axis_1/norm(axis_1);axis_2/norm(axis_2);axis_3/norm(axis_3)];
B2=[dir1_new(:),null(dir1_new)];
s=sign(det(B2));
B2=B2.*[1,1,s];
rotationMatrix=B2*B1;

Community Treasure Hunt

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

Start Hunting!

Translated by