C++ Game Development By Example
上QQ阅读APP看书,第一时间看更新

Cross product

Cross product is the other vector multiplication form in which the resultant product of the multiplication is another vector. Taking the cross product between  and  vectors will result in a third vector that it is perpendicular to both vectors  and  .

If you have two vectors,   = (ax, ay, az) and   = (bx, by, bz), then . is given as follows:

 = (ay bz - az by, az bx - ax bz, ax by - ay bx)

The following is a matrix and graphical implementation of the cross product between vectors:

       

The direction of the resultant normal vector will obey the right-hand rule, where curling the fingers in the right hand from  to  will cause the thumb to point in the direction of the resultant normal vector .

Also note that the order in which you multiply the vectors is important as if you multiply the other way around then the resultant vector will be a point in the opposite direction.

The cross product will become very useful when we want to find the normal of the face of a polygon. For example, finding the normal of the face of a triangle.

Let us find the cross product of vectors  = (3, -5, 7) and   = (2, 4 , 1):

C = A × B = (ay bz - az by, az bx - ax bz, , ax by - ay bx)

= (-5 * 1 - 7*4 , 7 * 2 - 3 * 1, 3 * 4 - (-5) * 2 )

= (-5-28, 14 - 3, 12 + 10)

= (-33, 11, 22)