# Get rotation around one axis

I have troubles finding a way to extract, from a quaternion, the “component” of the rotation around an arbitrary axis.
Any idea? :chimpanzee_nogood:

One of the three standard axes or an arbitrary axis?

Why do you need this thing? That’s probably a better place to start… because most answers will be wrong for half of the reasons you might want such a thing.

It’s the thing i tried to figure out on slack some time ago, the problem jumped out again.
In short i want to align a triangle to a surface normal but keep it’s direction
See the image below:

Green triangles pointing up is what i want to archive while the red one is what i have right now.

new Quaternion().lookAt(normal, Vector3f.UNIT_Y);

…works for anything that isn’t pointing straight up.

This is why I ask the question because 99% of the time “I need angles” is a sign of making the math more complicated.

Well… it seems it works, but i can’t understand why…
Isn’t lookAt(normal, Vector3f.UNIT_Y) supposed to bring me to this situation

where the red sphere has position (0,1,0)

?

Quaternion.lookAt() makes the Z axis of the reference frame point in the direction that you want to look. If your triangle is in x,y then lookAt does exactly what you want.

…and if your triangle wasn’t in x,y then that would have been my next suggestion.

1 Like

I just recognized I have overthought decals for quite to long …