# How to convert a rotation around an axis into pitch and yaw rotation

So i want to rotate particles towards a point and i've already figured out how to calculate the angle and the rotation axis.

Currently what i do is simply use a 3 dimensional matrix, apply the rotation and then extract the euleric angles from the matrix using joml.

Now using the result i have the problem that the particle is also using the z rotation, messing up the orientation of the particles texture. The easiest way to fix this would be to only use yaw and pitch, but how do i convert the roation to just a rotation around the x and y axis?

• Sounds like all you need to do is convert your facing direction vector into spherical coordinates. You can think of the theta and phi angles you get that way as yaw and pitch. We have lots of existing Q&A about that kind of conversion, or the Wikipedia article would have everything you need too (though they seem to use a form with phi = 0 at the pole. I'd exchange cosine for sine to place phi = 0 at the equator instead, but you can always just subtract π/2 instead) – DMGregory Feb 22 at 14:16
• What programming language are you using? And are you using Unity? – user124517 Feb 22 at 14:55
• I will take a look into spherical coordinate systems, thanks. And i'm using java and the math library joml – Masy Feb 22 at 15:00