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\$
2
  • \$\begingroup\$ What library is it? Are you sure it doesn't have any interchange methods? \$\endgroup\$ Commented Jul 29, 2013 at 21:07
  • \$\begingroup\$ Ogre3D, and I have no idea what methods to use \$\endgroup\$
    – Pacha
    Commented Jul 29, 2013 at 21:13

1 Answer 1

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

You must log in to answer this question.

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