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

192 views

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

In: 0

4 Answers

Anonymous 0 Comments

if you draw 2 vectors from the same point, the dot product is the vector that leads from the end of the first vector, to the end of the second vector. In game dev, vectors are normally normalized, on 2 normal vectors, the dot product can be thought of as “the difference of angles between the 2 vectors”. This is useful for things like knowing if the player is pointing at something or not since you can take the looking vector, and the vector to thing, normalize both and dot them together and you know how close the player is to looking at thing.

a vector cross product gives you a vector that is perpendicular to both input vectors that is the “area” between the vectors long. (in practice, this length is just normalized away) this is useful for things like “The player is pointing this way, and the ground is this way, so which direction is right next to the player?”

Anonymous 0 Comments

* If I have two vectors **a** and **b** then their cross product **a**x**b** will be perpendicular to both **a** and **b**, so you’d use it if you need to find a vector like that.
* The dot product spits out a number that essentially measures the angle between the two vectors, if I have vectors **a** and **b** with and angle t between them, then **a**.**b** = |**a**||**b**|cos(t), the way you actually calculate the dot product is fairly simple though, so it’s a way to get the angle between two vectors if all you have is two columns of numbers.

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.

Anonymous 0 Comments

The dot product multiplies the components of both vectors that are in the same direction. For example, if you have work equals force dot displacement, it’s the portion of the force that’s along the direction of the displacement. If there’s any force that’s perpendicular to the movement, it does no work, and the dot product ignores that component.

The cross product multiplies the components of both vectors that are perpendicular to each other. For example, angular momentum is momentum going around in a circle. You can determine it as position x momentum. This isolates the component of the momentum vector that’s “orbiting” around the origin, and ignores the component that’s going toward or away from the origin. The result is a vector perpendicular to both vectors you started with, which is a little weird, but the product can have two possible directions depending on which way the object is going around, so it’s relevant that it’s a vector.