Demystifying the Cross Product

  I've written about the dot product before. It's simple in implementation, but maybe you weren't sure what it's practically used for. The cross product, on the other hand, has the added dimension of being complicated to compute. It would be pretty difficult for someone to determine the cross product in their head! So, before we get into what the cross product is used for, let's recall how we compute it.

First, we need two vectors, let's call them a and b. When we compute the cross product between two vectors, we will end up with a resulting vector, we'll call that C. How do we get C?

C = <a.y*b.z - a.z*by, a.z*b.x - a.x*b.z, a.x*b.y - a.y*bx>

One way I like to remember this is - for every component in C, the other two components are used in the computation. For example, let's look at C.x.

C.x = a.y * b.z - a.z * b.y

Notice, this is for the 'x' component of C, and yet in the computation, only y and z components are used!

Important note: order matters for cross products, as you can see, there's subtraction going on!


OK. So, we know how to compute the cross product, but what does that do for us? What can the cross product tell us? Well, let's dive into that part.

The main useful quality of the cross product is the resulting vector is orthogonal to the two vectors you used for the computation. It is always exactly 90 degrees to the first two vectors! Sound familiar? It should. That's a quality in normals, which you may remember from my dot product post.

Credit to Wolfram: https://mathworld.wolfram.com/NormalVector.html



Because we're working in 3D space in computer graphics, we work with a lot of vectors, and as you can imagine, finding orthogonal vectors can come up often, even outside of the context of normals.

Normals are the big one, but there are other uses! Cross products come up a lot in rigid bodies and the motion of rigid bodies, as well as when dealing with torque in computational physics. 

So, there you have it. Hopefully this gave you a bit more insight into the cross product and why it's so relevant to the world of computer graphics. Normals are extremely important! 

Comments

Popular posts from this blog

Let's Implement a Gaussian Blur Algorithm in Python

Using Google Sheets Python API to Manage Scriptable Data in Unity