0
\$\begingroup\$

Assume said object is an aircraft. I store three angles (in degrees) that describe where it's headed: yaw, pitch and roll - in that order. Let's say the plane is flying vertically, upwards. The angles would then be: (0, 90, 0). Then, I command the plane to turn left; this results in the following angles: (0, 0, 90).

  1. Given the plane's current angles and a command (turn left, right, up, or down), how can I calculate its new angles?
  2. Would it be easier if I were using a directional vector and an extra "up" vector (i.e., the normal of the surface that cuts the plane in half, horizontally)?
\$\endgroup\$
2
  • \$\begingroup\$ The command to turn - is that asking the plane to apply the given angles relative to its local reference frame? (ie. pitch 90 up then yaw 90 left = yaw 90 left then roll 90 left) ...Euler angles are likely to cause unnecessary grief here. Have you considered using directional basis vectors, rotation matrices, or quaternions instead? These all compose under much more predictable rules and can more easily avoid gimbal lock problems which plague Euler angle setups. \$\endgroup\$
    – DMGregory
    Mar 11, 2016 at 13:55
  • \$\begingroup\$ Possible duplicate of What is a quaternion? \$\endgroup\$
    – Philipp
    Mar 11, 2016 at 14:02

2 Answers 2

2
\$\begingroup\$

Don't use Euler angles for that, you'll get in trouble with a Gimbal lock in some situation and you'll be clueless about what the angles will be doing.

I would suggest you use a space for your object, i.e. the option 2 you suggest. To make a space you need 3 vectors: the front vector, which represent the front of your model and the heading, and the side, which is arbitrarily left or right (be consistent across all of your system), in the case of a plane, it would represent one of the wings. From these 2 you can infer the 3rd vector with a cross product.

The vectors represent the local space of the plane in world space.

  • When you modify the yaw, you rotate the front and the side vectors w.r.t. the up vector.
  • When you modify the pitch, you rotate the front and the up vectors w.r.t. the side vector.
  • When you modify the roll, you rotate the side and the up vectors w.r.t. the front vector.

The cup-and-saucers in the following image each have their local space, just to give you an idea, and the 'central' gizmo shows you the global space: enter image description here

(Image source)

\$\endgroup\$
2
\$\begingroup\$

Don't use Euler angles for that, you'll get in trouble with a Gimbal lock in some situation and you'll be clueless about what the angles will be doing.

Instead, use Quaternions to both represent your current rotation and any changes to it.

Quaternions are often used to describe a rotation in 3d space by encoding:

  1. a rotation axis (in form of a 3-dimensional vector ê)
  2. how far to turn around that axis (in form of an angle θ)

Source:Wikipedia

By picking the rotation axis relative to the current heading of your object, you can get meaningful turning behavior from any existing rotation.

Quaternion math is quite complex, so I would recommend you to use a library for this.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .