Finding rotation angles from a normal

Started by
5 comments, last by Alessandro 13 years, 7 months ago
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
Advertisement
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).
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 ?
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.
Quit screwin' around! - Brock Samson
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.



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.

If your heightmap is made of quads formed by 2 triangles, you'll need to pick the right triangle based on your scales.

You might also want to add some random rotation about this new found y axis.
Thank you very much wforl, that helped to solve problem 2 !

This topic is closed to new replies.

Advertisement