So, I have code to create a quaternion from a matrix (using the 3x3 rotational part.)

And I have code to construct a transformation matrix from a lookat + up vector pair.

To go from lookat+up to quaternion, I can thus go via the matrix intermediary:

vec3 lookat;
vec3 up;
mat44 trf = mat44::create_basis( lookup, up );
quat ori = quat::from_matrix( trf );

So far, so good.

But can I do this without the matrix intermediary? Because it seems to inefficient. For starters, both the lookat+up and the quaternion are a lot more concise than the intermediate matrix. It goes from compact to large, to the most compact.

How can I create a quaternion using just a look-at vector and an up-vector, both of which are guaranteed to be unit length and perpendicular to each other.

  • \$\begingroup\$ Are you guaranteed the look at and up vectors are unit vectors, and exactly perpendicular, or do we have to accommodate cases that depart from this simplest version? \$\endgroup\$ – DMGregory Apr 4 '19 at 18:28
  • 1
    \$\begingroup\$ Is this similar to what you are looking for? math.stackexchange.com/questions/60511/… \$\endgroup\$ – Bálint Apr 5 '19 at 6:04

Your Answer

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

Browse other questions tagged or ask your own question.