0
\$\begingroup\$

I have a 2D vector (with only X and Y), and my engine only supports orientation through Quaternions.

How do I translate a 2D vector to a quaternion?

The X and Y represent the direction (so X = 0 and Y=1 means going forward, X=0.707 and Y=0.707 means rotate 45 degree, etc).

\$\endgroup\$
  • \$\begingroup\$ What library is it? Are you sure it doesn't have any interchange methods? \$\endgroup\$ – Seth Battin Jul 29 '13 at 21:07
  • \$\begingroup\$ Ogre3D, and I have no idea what methods to use \$\endgroup\$ – Pacha Jul 29 '13 at 21:13
2
\$\begingroup\$

In Ogre3d's docs:

void Ogre::Quaternion::FromAngleAxis(
    const Radian & rfAngle, const Vector3 & rkAxis )

Your rkAxis will always be UnitZ, because you are constraining yourself to the X-Y plane.

\$\endgroup\$
  • \$\begingroup\$ and the angle? How do I find it? \$\endgroup\$ – Pacha Jul 29 '13 at 21:20
  • \$\begingroup\$ It's the angle of rotation, and it is arbitrary. \$\endgroup\$ – Seth Battin Jul 29 '13 at 21:22
  • \$\begingroup\$ But how do I find the angle from a 2D vector? \$\endgroup\$ – Pacha Jul 29 '13 at 21:23
  • \$\begingroup\$ You have some options there, but it will probably involve arctangent \$\endgroup\$ – Seth Battin Jul 29 '13 at 21:25
  • \$\begingroup\$ it is better to store the rotation/orientation and calculate the direction from it if possible \$\endgroup\$ – Quonux Jul 29 '13 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.