![](wink.gif)
Normal Rotation..
Hey ppl..
Say i have a quad drawn up on screen, which has the normal (1,0,1). How would i find the normal, of the same quad, if it had just been rotated a certain angle programmatically?
For example, i had a quad with normal (1,0,1) which is then rotated 90 degrees around the x axis.
If you understood this question, please feel free to help
cheers
-- wAVaRiaN
![](wink.gif)
To get the new normal, apply the same rotation to the normal as you do to the plane.
You have a polygon P, with initial orientation n0. If you rotate the polygon with a matrix R, the new normal is R*n0.
If matrices aren''t your thing, here are some quick equations:
cq = cos(q), sq = sin(q)
n0 is the original normal
n1 is the new normal
rotate about x by angle q:
n1[0] = n0[0]
n1[1] = n0[1]*cq - n0[2]*sq
n1[2] = n0[1]*sq + n0[2]*cq
rotate about y by angle q:
n1[0] = n0[0]*cq + n0[2]*sq
n1[1] = n0[1]
n1[2] = -n0[0]*sq + n0[2]*cq
rotate about z by angle q:
n1[0] = n0[0]*cq - n0[1]*sq
n1[1] = n0[0]*sq + n0[1]*cq
n1[2] = n0[1]
If you''re doing multiple rotations, calculate a new normal after each one (n1, n2, n3) -- don''t try to do them all at once this way.
Hope this helps.
You have a polygon P, with initial orientation n0. If you rotate the polygon with a matrix R, the new normal is R*n0.
If matrices aren''t your thing, here are some quick equations:
cq = cos(q), sq = sin(q)
n0 is the original normal
n1 is the new normal
rotate about x by angle q:
n1[0] = n0[0]
n1[1] = n0[1]*cq - n0[2]*sq
n1[2] = n0[1]*sq + n0[2]*cq
rotate about y by angle q:
n1[0] = n0[0]*cq + n0[2]*sq
n1[1] = n0[1]
n1[2] = -n0[0]*sq + n0[2]*cq
rotate about z by angle q:
n1[0] = n0[0]*cq - n0[1]*sq
n1[1] = n0[0]*sq + n0[1]*cq
n1[2] = n0[1]
If you''re doing multiple rotations, calculate a new normal after each one (n1, n2, n3) -- don''t try to do them all at once this way.
Hope this helps.
JohnFifty1 Software
Easiest way to find a normal is to take the cross product of the two vectors.
To find a vector as placed at the origin, take it''s endpoints and subtract one from the other (remember, direction counts)
if you wanted to find vectorOA and vectorOB as translated to the origin so they may be represented by a single set of (x, y, z) coords, then you would do the following...
Lets pretend that,
O = (5, 2, 1)
A = (3, 6, 6)
B = (6, 3, 4)
That would mean that...
vectorOA = (3-5, 6-2, 6-1) or (-2, 4, 5)
vectorOB = (6-5, 3-2, 4-1) or (1, 1, 3)
OA X OB (vectorOA cross vectorOB, remember, to cross to vectors they must have the same starting point, so you couldn''t cross vectorOA with vectorBO...)
= (OA.y*OB.z - OA.z*OB.y, OA.z*OB.x - OA.x*OB.z, OA.x*OB.y - OA.y*OB.x)
= (4*3 - 5*1, 5*1 - (-2)*3, (-2)*1 - 4*1)
= (7, 11, -6)
let''s call that vectorOC.
then if you want a unit vector in that direction, find the magnitude and divide the vector by that.
magnitude of vectorOC = sqrt(7*7 + 11*11 + (-6)*(-6))
= sqrt(49 + 121 + 36)
= sqrt(206)
therefor, unit vector in direction of vectorOC is
(7 / sqrt(206), 11 / sqrt(206), -6 / sqrt(206))
That should give you a start on vectors and cross products, etc. if you haven''t had it in school yet.![](smile.gif)
S.
To find a vector as placed at the origin, take it''s endpoints and subtract one from the other (remember, direction counts)
if you wanted to find vectorOA and vectorOB as translated to the origin so they may be represented by a single set of (x, y, z) coords, then you would do the following...
Lets pretend that,
O = (5, 2, 1)
A = (3, 6, 6)
B = (6, 3, 4)
That would mean that...
vectorOA = (3-5, 6-2, 6-1) or (-2, 4, 5)
vectorOB = (6-5, 3-2, 4-1) or (1, 1, 3)
OA X OB (vectorOA cross vectorOB, remember, to cross to vectors they must have the same starting point, so you couldn''t cross vectorOA with vectorBO...)
= (OA.y*OB.z - OA.z*OB.y, OA.z*OB.x - OA.x*OB.z, OA.x*OB.y - OA.y*OB.x)
= (4*3 - 5*1, 5*1 - (-2)*3, (-2)*1 - 4*1)
= (7, 11, -6)
let''s call that vectorOC.
then if you want a unit vector in that direction, find the magnitude and divide the vector by that.
magnitude of vectorOC = sqrt(7*7 + 11*11 + (-6)*(-6))
= sqrt(49 + 121 + 36)
= sqrt(206)
therefor, unit vector in direction of vectorOC is
(7 / sqrt(206), 11 / sqrt(206), -6 / sqrt(206))
That should give you a start on vectors and cross products, etc. if you haven''t had it in school yet.
![](smile.gif)
S.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement