<p>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.</p>

<p>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).</p>

<p>So, it'll be something like this:</p>

<pre><code>// 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); 
</code></pre>

CC BY-SA 3.0
2017-09-11T21:24:46.673Z
2017-09-11T22:48:32.167Z
2017-09-11T22:48:32.167Z
Alan Wolfe
<p>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? </p>

CC BY-SA 3.0
2017-09-30T18:56:15.260Z
Cross x and y and you will get your z axis assuming x and y are perpendicular
ChaoSXDemon
<transformations>
How to rotate an object around any axis if i have just local x and y?
Vektast
# How to rotate an object around any axis if i have just local x and y?

(Asked by: username_0 on 2017-09-11)

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?

**Tags:** transformations

> **Comments:**
> **username_1**: Cross x and y and you will get your z axis assuming x and y are perpendicular  

---

## 1 answers

### Answer by username_2 on 2017-09-11. Score: 1

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); 

```


---

