Sign in to follow this  

Finding rotation angles from a normal

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

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.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this