Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Euler angles between two 3d vectors

How do you find the 3 euler angles between 2 3D vectors? When I have one Vector and I want to get its rotation, this link can be usually used: Calculate rotations to look at a 3D point?

But how do I do it when calculating them according to one another?

like image 885
tomyake Avatar asked Feb 26 '13 22:02

tomyake


People also ask

How do you find the angle between 2 3D vectors?

To calculate the angle between two vectors in a 3D space: Find the dot product of the vectors. Divide the dot product by the magnitude of the first vector. Divide the resultant by the magnitude of the second vector.

What are the 3 Euler angles?

The relative orientation between two orthogonal righthanded 3D cartesian coordinate systems, let's call them xyz and ABC, is described by a real orthogonal 3x3 rotation matrix R, which is commonly parameterized by three so-called Euler angles α, β and γ.

How do you find Euler angles?

Given a rotation matrix R, we can compute the Euler angles, ψ, θ, and φ by equating each element in R with the corresponding element in the matrix product Rz(φ)Ry(θ)Rx(ψ). This results in nine equations that can be used to find the Euler angles. Starting with R31, we find R31 = − sin θ.

How do you find the rotation between two vectors?

First step, you want to find the angle between the two vectors using the dot product. Next, to find the axis of rotation, use the cross product. Knowing that the cross product will yield a vector perpendicular to both u and v , crossing them in either order will give an appropriate axis.


2 Answers

As others have already pointed out, your question should be revised. Let's call your vectors a and b. I assume that length(a)==length(b) > 0 otherwise I cannot answer the question.


Calculate the cross product of your vectors v = a x b; v gives the axis of rotation. By computing the dot product, you can get the cosine of the angle you should rotate with cos(angle)=dot(a,b)/(length(a)length(b)), and with acos you can uniquely determine the angle (@Archie thanks for pointing out my earlier mistake). At this point you have the axis angle representation of your rotation.

The remaining work is to convert this representation to the representation you are looking for: Euler angles. Conversion Axis-Angle to Euler is a way to do it, as you have found it. You have to handle the degenerate case when v = [ 0, 0, 0], that is, when the angle is either 0 or 180 degrees.


I personally don't like Euler angles, they screw up the stability of your app and they are not appropriate for interpolation, see also

  • Strange behavior with android orientation sensor

  • Interpolating between rotation matrices

like image 122
Ali Avatar answered Sep 21 '22 10:09

Ali


At first you would have to subtract vector one from vector two in order to get vector two relative to vector one. With these values you can calculate Euler angles.

To understand the calculation from vector to Euler intuitively, lets imagine a sphere with the radius of 1 and the origin at its center. A vector represents a point on its surface in 3D coordinates. This point can also be defined by spherical 2D coordinates: latitude and longitude, pitch and yaw respectively.

In order "roll <- pitch <- yaw" calculation can be done as follows:

To calculate the yaw you calculate the tangent of the two planar axes (x and z) considering the quadrant.

yaw = atan2(x, z) *180.0/PI;

Pitch is quite the same but as its plane is rotated along with yaw the 'adjacent' is on two axis. In order to find its length we will have to use the Pythagorean theorem.

float padj = sqrt(pow(x, 2) + pow(z, 2)); 
pitch = atan2(padj, y) *180.0/PI;

Notes:

  • Roll can not be calculated as a vector has no rotation around its own axis. I usually set it to 0.
  • The length of your vector is lost and can not be converted back.
  • In Euler the order of your axes matters, mix them up and you will get different results.
like image 45
Vectasus Avatar answered Sep 22 '22 10:09

Vectasus