# Finding rotation angles from a normal

This topic is 2856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, sorry if this is a newbie question, but it's really puzzling me since I have a very modest math knowledge.

I would like to know or to see an example of how to calculate the 3 rotation angles for a vertex point, knowing its normal.

For example, if I have a point at (0,0,0) and it's normal is (0,1,0), the vector is pointing up and the rotation angles would be theta=90, psi=0, phi=0

That of course is easy to guess since it's a very simple example, so I hope somebody could explain how to arrive to that result...
Thanks

##### Share on other sites
The problem as you're describing it is not possible to solve. The normal can only fix two of the three angles, but the third one (the angle effectively rotating about the normal itself) cannot be determined, since there's nothing constraining the rotation of the normal about itself. A solution to the first two angles can have any third angle, since it will just rotate the axes around the normal itself, while still satisfying the solution.

If you want three angles, there must be something else constraining the third angle once two are calculated. Alternatively, you only want two angles and some constraint on how these angles satisfy the solution (for example, smallest possible rotation angles).

##### Share on other sites
Thanks for your answer Bob. What if I'd not care about the rotation angle around the normal, and I'd just like to gather the other two ?

##### Share on other sites
You can find both angles individually using an arctangent (known in some math libraries as atan()). You'll need to run a couple of comparisons on the position to figure what quadrant the angle is in and adjust the return value accordingly. So, atan(y/x) and atan(z/x) should give you something to work with.

What are you using this for? This is computationally expensive and I usually manage to avoid the problem entirely using some other method. On the other hand, if you're only performing the calculation once per frame, eg: display angle to target, then it's not a big deal.

##### Share on other sites
Well, I prepared an image that should explain better what I'm trying to do.

Basically is a terrain with some objects deployed on it.

First problem: object are deployed vertical to ground plane (red ones), while I'd like to have them perpendicular to it (green ones).

Second problem: I also need to retrieve coordinates for points lying inside terrain quads, like A5. It's no problem to get x and z coordinates, but how could I calculate the height ? Vector math ?

Second problem is way more important, while the first, well, I could skip it.

Thank you very much for any help.

##### Share on other sites
For problem one, I'd create a basis, such as

x = A4 - A1
z = A2 - A1
y = Cross( x, z )

And then problem two uses the same x,z

NewPoint = A1 + ( Scale*x + Scale*z );

Where scale is between 0 and 1. Where you then position the basis at NewPoint for the final transform.

##### Share on other sites
Thank you very much wforl, that helped to solve problem 2 !

1. 1
2. 2
3. 3
Rutin
21
4. 4
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631778
• Total Posts
3002308
×