Get the Angle of a Normal

BlitzMax Forums/BlitzMax Programming/Get the Angle of a Normal

Damien Sturdy(Posted 2006) [#1]
Hi there.

I need to find the angle that a normal lies at.

X=0,Y=1,Z=0 would produce Pitch=-90, Yaw=0, Roll=0 for instance.

I'm asking here since it's for a Max project- Does anyone know how to do this, or where to grab some info on it?

Thanks all!


AlexO(Posted 2006) [#2]
http://www.answers.com/main/ntquery;jsessionid=aaal450gft6pe?method=4&dsid=2222&dekey=Euler+angles&curtab=2222_1&sbid=lc05a&linktext=Euler%20angles

^Is that what you are asking about? If so, then looking at how Euler Angles are computed would probably be the solution.

Quote from site:

"Euler angles are the classical way of representing rotations in 3-dimensional Euclidean space...In common parlance, "rotation" refers to a physical motion of some object about a pivot or axis"


Damien Sturdy(Posted 2006) [#3]
An interesting read, however, i'm unable to link that to what i need to get. Perhaps it's there but i just don't understand?

Basically i'm turning a linear velocity into an angle.


sswift(Posted 2006) [#4]
Atan2(Ny#, Nx#)

That will work for a vector of any length. Make sure Ny# goes first.


Damien Sturdy(Posted 2006) [#5]
Aha, we're getting there- Thanks Sswift. Now, how could I do that in 3D?

I'm clueless at this stuff. It's B3D's fault! :P

I know where the object is going, in the X Y and Z direction. i need to know the angle from 0,0,0.

Imagine;

Your car is on a ramp, you know where the ramp is pointing (The NX,NY and NZ in B3D). You need to know the angle however in order to align the car to the ramp.

(PS, no, I am using Max and not b3D here :) )

[edit] I'm right in thinking it'd be just two more pieces of code almost the same as above?


sswift(Posted 2006) [#6]
I can't help you with that unfortunately. That's much more complicated.

My example was for 2D, I didn't realise you were doing 3D stuff. You could do that 2D calculation twice for 3D but that's not going to tell you yaw pitch and roll.

I'm not even sure how you should determine roll in that case actually.


Chris C(Posted 2006) [#7]
damn I used this in somthing for glancing collisions in somthing and I have forgot how i got it

from memory you can get the normal of the surface from a cross product of a tri's vert's

i'm on my laptop at the moment, but theres plenty of stuff to get you going for calculating stuff like that on the internet

I *think* the chase sample (on my site) might have some normal code in the vector lib extract that is included with it, so have a look!

Its not always the nightmare it might seem, look also on opengl lighting that relies on surface normals...


sswift(Posted 2006) [#8]
You can indeed get the normal of a surface from the cross product of the tri's verts, but that only tells you the direction which the Y axis of your object should point when on the surface.

The big problem here is this isn't how you're supposed to simulate vehicles on surfaces. :-) It's all much simpler if you simply pull each wheel downward and stop when it hits something, and then calculate the angle of the car from that each frame. But to so that I'd use align to vector, which he doesn't have. :-)


N(Posted 2006) [#9]
http://www.euclideanspace.com/maths/geometry/rotations/euler/index.htm

Read the section on rotations about a single axis. Should at least get you started.


Damien Sturdy(Posted 2006) [#10]
Cheers guys.

That's something to read (and Choke on) on my lunch Noel :D