Chapter 2: Trigonometric Functions

text only
progress indicator progress indicator progress indicator progress indicator

Vector Cross Product

The cross product of two vectors is the most common vector operation in the second half of this book. Computing the cross product of two vectors gives you a third vector that is perpendicular to both of the original vectors. To visualize this, imagine three points in space as in Figure B.1. Mathematically speaking, those three points define a plane for which there is only one perpendicular "up direction". Using those three points, we can get two vectors, V ab and V ac . The cross product of those two vectors is perpendicular to the two vectors and is therefore perpendicular to the plane.


Figure B.1: The cross product of two vectors.

The cross product of two vectors is computed as follows :

It is important to note here that the vector N is perpendicular to the two vectors, but it is not necessarily a unit vector. You may need to normalize N to obtain a unit vector. This is the easiest way to find the vector that is perpendicular to a surface-something very necessary in lighting and shading calculations. It is also important to note that the cross product is not commutative. Changing the order of operations changes the sign of the cross product.

When you are computing surface normals, you may find that the wrong side of the surface is being lit. If this is the case, you've probably computed the cross product in the wrong order. Whenever your lighting doesn't look right, double-check your cross products before you start dissecting other parts of your code.

progress indicator progress indicator progress indicator progress indicator


Focus on Curves and Surfaces
Focus On Curves and Surfaces (Focus on Game Development)
ISBN: 159200007X
EAN: 2147483647
Year: 2003
Pages: 104
Authors: Kelly Dempski

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net