![]() We already have the point (P), so all we need now is a vector in the direction of. To matrix conversion here we get: 1 - 2*qy 2 - 2*qz 2 If v1 and v2 are not already normalised then multiply by |v1||v2| gives: For example, the tutorial 'RSL: Edge Effects' applies normalization before calculating the dot product of two vectors. If v1 and v2 are already normalised then |v1||v2|=1 so, Operations in 2D and 3D computer graphics are often performed using copies of vectors that have been normalized ie. Page: cos(angle/2) = sqrt(0.5*(1 + cos (angle)))īecause |v1 x v2| = |v1||v2| sin(angle) we can normalise (v1 x v2) by dividingĪlso apply v1v2 = |v1||v2| cos(angle)so, Now substitute half angle trig formula on this Multiply x,y,z and w by 2* cos(angle/2) (this will de normalise the quaternion Later on, well see how to get n from other kinds of data. So substituting in quaternion formula gives: To describe a plane, we need a point Q and a vector n that is perpendicular to the plane. Page: sin(angle/2) = 0.5 sin(angle) / cos(angle/2) We can use this half angle trig formula on this The axis angle can be converted to a quaternion as follows, let x,y,z,w beĮlements of quaternion, these can be expressed in terms of axis angle as explained This is a bit messy to solve for q, I am therefore grateful to minorlogic for the following approach which converts the axis angle result to a quaternion: p 1= is a vector representing a point before being rotated.q = is a quaternion representing a rotation.p 2 = is a vector representing a point after being rotated.However, to rotate a vector, we must use this formula: This almost works as explained on this page. One approach might be to define a quaternion which, when multiplied by a vector, rotates it: In theġ80 degree case the axis can be anything at 90 degrees to the vectors so there Not matter and can be anything because there is no rotation round it. X v2 will be zero because sin(0)=sin(180)=0. If the vectors are parallel (angle = 0 or 180 degrees) then the length of v1 So, if v1 and v2 are normalised so that |v1|=|v2|=1, then, Two vectors, the length of this axis is given by |v1 x v2| = |v1||v2| sin(angle). the axis is given by the cross product of the. ![]() Of the two (normalised) vectors: v1v2 = |v1||v2| cos(angle) the angle is given by acos of the dot product. ![]() This is easiest to calculate using axis-angle representation because: using:Īngle of 2 relative to 1= atan2(v2.y,v2.x) - atan2(v1.y,v1.x)įor a discussion of the issues to be aware of when using this formula see the page here. If we want a + or - value to indicate which vector is ahead, then we probably need to use the atan2 function (as explained on this page). In most math libraries acos will usually return a value between 0 and π ( in radians) which is 0° and 180°. In other words, it won't tell us if v1 is ahead or behind v2, to go from v1 to v2 is the opposite direction from v2 to v1. The only problem is, this won't give all possible values between 0° and 360°, or -180° and +180°.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |