View Single Post
Old 11th July 2008, 09:50 AM   #4
lisa
Senior Member
Professional user
 
lisa's Avatar
 
Join Date: Mar 2005
Location: Phoenix, AZ
Posts: 917
Default Re: Output the angles, x,y,z

Use your two vertices to construct a vector. Construct a second vector that is the axis you want to find the angle between.

Normalize both vectors and take the dot product of the two vectors. The arccosine of the dot product is the angle in radians between the two vectors. Remember this is along the plane formed by the two vectors, so adjust accordingly.

Another (better) way to do it is to use your vector to construct an orientation matrix. As before, construct a vector from your two endpoints. This is your look vector. Normalize the vector. Assign an arbitrary up vector (generally 0,1,0 unless your look vector is parallel to this). Take the cross product between the look vector and the up vector which will give you a perpendicular. This is the right vector. Normalize the right vector. Take the cross product between the right vector and the look vector. This will give you a corrected up vector. Normalize it. You now have all three vectors required to construct an orientation matrix. Each vector forms one row (or column, depending on if you are row-major or column-major) of your 3x3 orientation matrix.

You can convert from an orientation matrix to Euler angles if you need with the equation here:
http://www.euclideanspace.com/maths/...uler/index.htm
lisa is offline   Reply With Quote