1
$\begingroup$

I have just two local axis to rotate a 3D object: X (horizontal) and Y (vertical). How to make from this 2 local axises for example a global Y rotation or a Local Z rotation? What math magic do the trick?

$\endgroup$
  • $\begingroup$ Cross x and y and you will get your z axis assuming x and y are perpendicular $\endgroup$ – ChaoSXDemon Sep 30 '17 at 18:56
1
$\begingroup$

If you know how to make a rotation matrix from X,Y,Z basis vectors (just make them the rows or columns, depending on whether you are using a row or column major matrix), you can do that, using the cross product of X and Y to get the Z vector.

The order of X and Y in the cross product depend on whether you are using a left or right handed coordinate system, but if you are unsure about this, you can check if doing Z=cross(X,Y) looks right and if not, switch to Z=cross(Y,X).

So, it'll be something like this:

// May be Y,X instead, depending on your handedness
Z = Cross(X,Y);

// May need to be transposed based on you using row or column major matrices
RotationMatrix = MatrixFromRows(X,Y,Z); 
$\endgroup$

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.