Eli5: Vector dot and cross products, what they are and what they’re used for

196 views

Trying to wrap my head around some mathematical concepts for game dev, thank you 🙂

In: 0

4 Answers

Anonymous 0 Comments

The dot and cross products are how we multiply vectors together.

Vectors are maths things (like numbers) but with more numbers in them – they have components which depend on our perspective (or the base system we’re using for those vectors).

We have two different ways of multiplying vectors, which for simpler, geometry-based vector involves telling us about how much of them is in the same direction or the opposite direction of each other.

The *dot* product (or *scalar* product) gives us just a number. It tells us how much of one vector is in the direction of the other. You multiply the magnitudes of each vector together (as you would if they were normal numbers), and then scale that by the angle between them (specifically the cosine of that angle). If they are in the same direction that gives you 1 (so you are just multiplying them together), if they are at right angles that gives you 0 (so you get nothing – a key use of the dot product is that a.b = 0 <=> a and b are at right angles to each other). You can also use the dot product to figure out the angle between two vectors.

The *cross* product (or *vector* product) gives you a vector. This vector is at right angles to both your other vectors (and in a right-handed sense), and its magnitude is given by the sine of the angle between them (so it starts at 0 and reaches it maximum at a right angle). More specifically the magnitude gives you the area of the parallelogram you get by joining up the vectors. If the vectors are in the same direction (or opposite direction) you get a x b = 0, if they are at right angles you get a vector whose magnitude is the magnitudes of the two vectors multiplied together. [Here] is a handy little animation showing how the cross product works.

Depending on what you’re doing with them you’ll find all sorts of uses.

In 3d geometry they are really useful for working with planes; a plane is (usually) defined by a unit vector (so with magnitude 1) at right angles to the plane (or similarly, a surface is defined by splitting it up into an infinite number of infinitely small surface elements, each defined by the vector at right angles to it). Given any plane, there are only two unit vectors perpendicular to it, so that is a neat way to define it.

If you have two vectors on your plane you can use the vector product to find a vector perpendicular to it to use to define it. Once you have that vector you can use the dot product to check whether any position vector is on your plane.

If you are doing physics modelling the dot product is really useful for resolving forces etc.; if you have some motion in 2d (or 3d) and you want to split it up into the three base directions and treat each part separately, doting your force/acceleration/velocity/displacement vectors with each of your base directions (so (1,0,0), (0,1,0) and (0,0,1)) will give you the component of your thing in that direction. It is an easy way to turn a vector problem into a series of one-dimensional/linear problems. The cross product is useful for doing anything involving rotations; we can define a rotation by a vector on the axis of rotation – which will be at right angles to various vectors involved, so cross products can help us find that.

You are viewing 1 out of 4 answers, click here to view all answers.