Converting from Yaw,Pitch,Roll to Vector

15.4k Views Asked by At

I am currently trying to construct a vector in space given yaw, pitch, and roll with the assumption that my ray originates from (0,0,0).

I started by breaking up the problem into 3 sets of triangles by slicing space in 3 ways:

  • In the X-Y plane, I concluded that x = sin(yaw) and y = cos(yaw)
  • In the Y-Z plane, I determined that y = cos(pitch) and z = sin(pitch)
  • In the X-Z plane, I found that x = cos(pitch) and z = sin(pitch)

From this, I arrived at enter image description here

However, this doesn't seem to satisfy basic tests, such as <1,1,1>, where the Yaw = Pi/4 and the Pitch should be Pi/4, but the formula yields 0.5, 0.5, 0.7, which has a direction vector different than <1,1,1>. Can anyone spot where I messed up? I've been banging my head at this for a while, and I can't seem to resolve where I made an error.

1

There are 1 best solutions below

1
On

enter image description here

I'll use the OMAF coordinate system which defines the viewer looking out the $x$-axis with $z$-axis up and the $y$-axis to the left. Given a yaw angle $\phi$ and a pitch angle $\theta$ we transform the direction vector $(u,v,w)$ onto the view axis $(1,0,0)$ by first performing a clockwise rotation about the $z$-axis by $\phi$ followed by a counter-clockwise rotation about the $y$-axis by $\theta:$ $$ \left[\begin{array}{c}1\\0\\0\end{array}\right] = R_y(\theta) \cdot R_z(-\phi) \left[\begin{array}{c}u\\v\\w\end{array}\right] $$

We then solve for $(u,v,w)$ and get $$ \left[\begin{array}{c}u\\v\\w\end{array}\right] = R_z(\phi) \cdot R_y(-\theta) \left[\begin{array}{c}1\\0\\0\end{array}\right] $$

$$ \left[\begin{array}{c}u\\v\\w\end{array}\right] = \left[\begin{array}{ccc}\cos\phi & -\sin\phi & 0 \\ \sin\phi & \cos\phi & 0\\ 0 & 0 & 1 \end{array}\right]\left[\begin{array}{ccc}\cos\theta & 0 & -\sin\theta \\ 0 & 1 & 0 \\ \sin\theta & 0 & \cos\theta \end{array}\right] \left[\begin{array}{c}1\\0\\0\end{array}\right] = \left[\begin{array}{c}\cos\phi\cos\theta \\ sin\phi \cos\theta \\ \sin\theta \end{array}\right] $$

which is your classical spherical to cartesian transformation where $\phi$ is the azimuthal angle and $\theta$ is the elevation angle. Note that the roll angle does not enter into the equation since it merely defines a rotation about the direction vector which does not alter the direction vector.

If you happen to be using OpenGL conventions where the viewer is looking out the $-z$-axis and the $y$-axis is "up" and the $x$-axis is to the right you will use the direction $(u',v',w') = (-v,w,-u).$