What Does a Dot Product Represent, Exactly?

A dot product boils two arrows down to a single number that says how much they agree in direction. That number equals one vector’s length times the length of the other’s shadow along it, so it grows with length and with alignment. The same value can be found two very different ways, by multiplying matching entries and adding, or from the arrows’ lengths and the angle between them, and both always agree.1Wikipedia. Dot product That double identity is why one small calculation quietly runs physics formulas, video game lighting, and the search engines and chatbots that compare meanings.

The Picture Behind The Number

Geometrically, the dot product of two vectors (arrows with a length and a direction, which can also be written as lists of numbers) is the product of their lengths and the cosine of the angle between them.1Wikipedia. Dot product Written out, u·v = |u||v|cos θ, where θ is the angle between the arrows.2OpenStax. What Does a Dot Product Represent, Exactly? The cosine is 1 when the arrows line up, 0 at a right angle, and -1 when they point opposite ways.

The question the dot product answers is how much of vector a points in the direction of vector b.3Math Insight. What Does a Dot Product Represent, Exactly? The length |a|cos θ is the length of a’s shadow on b’s line, which is called the projection of a onto b. The dot product is that shadow length multiplied by b’s length. If b has length 1, the dot product is exactly the shadow length.

Tilt a toward b and the shadow lengthens; tilt it away and it shortens. When a stands straight up from b, the shadow shrinks to a point.

The dot product is symmetric, so a·b equals b·a. The shadow of a on b times |b| equals the shadow of b on a times |a|, which means you can pick whichever view is easier to picture.

A small example makes this concrete. Take a = (3, 0) and b = (2, 2), which sit 45 degrees apart. Their lengths are 3 and about 2.83, and cos 45° is about 0.707. Then 3 × 2.83 × 0.707 gives about 6. From the other side, b’s shadow on a has length 2, and 2 × 3 is 6 too.

The dot product can also be negative. When the angle between the arrows is more than 90 degrees, a’s shadow lands on the opposite side of b’s tail, behind the direction b points. The shadow length is then counted as negative, which is exactly what a negative cosine does to the product of lengths.

Why Multiply And Add Gives The Same Answer

Algebraically, the dot product is the sum of the products of matching entries.1Wikipedia. Dot product In coordinates, A·B = a1b1 + a2b2 +… + aNbN, and it also equals |A||B|cos θ.4MIT OpenCourseWare. Dot Products The two definitions agree when you use ordinary perpendicular coordinates.1Wikipedia. Dot product

The proof starts by drawing the third side C = A − B of the triangle formed by A and B.4MIT OpenCourseWare. Dot Products Place the two arrows tail to tail and they form two sides of a triangle, with θ as the angle opposite the third side. The law of cosines links that third side’s length to the other two sides and θ, so it is the geometric statement the proof compares against.

Now expand C’s squared length in coordinates. You get squares of A’s entries, squares of B’s entries, and a cross term made of products of matching entries. The squared-entry parts match the |A|² and |B|² in the law of cosines, so the only thing left to match is the cross term. Comparing the two expressions gives 2A·B = 2|A||B|cos θ.4MIT OpenCourseWare. Dot Products

Basis arrows give another view of why the sum works. Each axis arrow has length 1 and is perpendicular to the others, so an axis arrow dotted with itself is 1 and with another axis is 0. Expanding a·b axis by axis, every mixed term vanishes. Only a1b1, a2b2 and so on survive.

Each form is handy in different situations. Use the sum when you have coordinates, which computers always do. Use lengths and cosine when you know an angle, as in physics diagrams. Combine them to find an angle: cos θ equals a·b divided by |a||b|.

What Positive Zero And Negative Mean

  • Positive: the vectors point in generally the same direction.5Engineering Statics. Engineering Statics
  • Zero: the vectors are perpendicular, also called orthogonal.6Ximera. The dot product
  • Negative: the vectors point in generally opposite directions.5Engineering Statics. Engineering Statics

You can check perpendicularity without ever computing an angle.3Math Insight. What Does a Dot Product Represent, Exactly? Take (1, 2) and (-2, 1): the products are -2 and 2, which add to 0, so the vectors are perpendicular. No protractor or cosine table needed, and this is how programs check right angles quickly.

The sign alone tells you about direction agreement. The size mixes agreement with length, so two long, loosely aligned vectors can beat two short, perfectly aligned ones.

Exactly zero is a slightly special case. It happens when cos θ is zero, a 90 degree angle, but it also happens when one vector is the zero vector with no length at all. The zero vector has no direction, so this test treats it as perpendicular to everything. In software, a result very close to zero but not exactly zero may mean nearly perpendicular, since small rounding errors are common with decimals, but it can also come from very short vectors, so dividing by the lengths first gives a fairer test.

Work And Flux In Physics

Work done by a constant force equals force dotted with displacement.7Flipping Physics. Work as the Dot Product Only the part of the force along the motion does work, so work is F times distance times cos θ.8University Physics Volume 1. Work Pushing at a right angle to the motion does no work at all.

Pulling a suitcase by its handle shows this. You pull up and forward at an angle, but only the forward part moves the suitcase along the floor. The upward part strains your arm and adds no work, so a lower handle angle wastes less effort.

Work can also be negative. If the force has a part pointing against the motion, the dot product is negative and so is the work. Friction is the everyday example: it points opposite to the sliding, so it takes energy out of the moving object. Anything past 90 degrees, like braking, gives negative work.

Flux works similarly. When a flow hits a surface at angle θ to the arrow sticking straight out of it, only the j cos θ part passes through.9Wikipedia. Flux The sideways part, j sin θ, slides along the surface and does not cross it.9Wikipedia. Flux So flux is a dot product of the flow with that outward arrow.

Lighting And Hidden Surfaces In Graphics

Matte surface brightness comes from the dot product of the surface’s outward arrow, the normal vector, and the direction to the light, both length 1.10PubMed. Lambertian reflectance A surface facing the light head-on is brightest, and one edge-on to it goes dark.

When the dot product of the outward arrow and the light direction is negative, the surface faces away from the light. A negative brightness makes no physical sense, so graphics code typically sets those values to zero and leaves the surface dark.

Graphics systems also often discard any surface whose outward arrow dotted with the line of sight is zero or more.11Wikipedia. Back-face culling Such surfaces face away from the viewer and can’t be seen.11Wikipedia. Back-face culling The test is cheap, needing only one dot product, so it removes many surfaces early.11Wikipedia. Back-face culling

Game physics leans on the same tool for collisions. A game needs to know how much of the closing speed is along the line of impact, and the dot product of relative velocity with the impact direction gives it. Bounciness then scales how much of that speed reverses.

Measuring Similarity In Search And AI

Cosine similarity divides the dot product by both lengths, leaving only the angle’s cosine.12DEJAN. Cosine Similarity or Dot Product? When vectors are scaled to length 1 first, cosine similarity and the dot product are the same number.12DEJAN. Cosine Similarity or Dot Product? It is the standard way to compare word and document vectors.13University of Freiburg. A review of word embedding and document similarity algorithms applied to academic text

In a word comparison, each word becomes a list of hundreds of numbers. Words used in similar contexts end up pointing similar ways, so their dot product after length scaling is close to 1. Unrelated words score near 0.

The plain dot product rewards long vectors, while cosine similarity ignores length. Use cosine similarity when only meaning should count.

Transformer models score how relevant one piece of text is to another with a dot product of a query and a key vector.14arXiv. Alternatives to the Scaled Dot Product for Attention in the Transformer Neural Network Architecture Raw dot products grow large in long vectors, so they are divided by the square root of the vector length before use.14arXiv. Alternatives to the Scaled Dot Product for Attention in the Transformer Neural Network Architecture Very large scores stop the model from learning well.14arXiv. Alternatives to the Scaled Dot Product for Attention in the Transformer Neural Network Architecture

The reason is that a dot product adds up one product for every entry, so a vector with many entries gives bigger sums just because there are more terms. Dividing by the square root of the length keeps the typical score the same size however long the vectors are.

Language models also appear to store separate concepts as almost perpendicular directions in very high-dimensional spaces.15arXiv. A short survey on almost orthogonal vectors in a few specific large dimensions A dot product near zero then signals unrelated ideas.

Matrices Are Many Dot Products At Once

Multiplying two matrices takes dot products between rows of the first and columns of the second.16Built In. What Does a Dot Product Represent, Exactly? The entry in row i, column j is row i dotted with column j.17Medium. 3 Ways to Understand Matrix Multiplication A single row works like a machine that flattens any vector to one number on a line.18Medium. Understanding the Dot Product, Duality, and Vector Projections

A small example: take rows (1, 2) and (3, 4) times the column (5, 6). The first entry is 1×5 + 2×6 = 17, and the second is 3×5 + 4×6 = 39. Each answer is a separate dot product.

Signals And Curved Space

Cross-correlation measures how similar two signals are as one slides past the other, and is also called a sliding dot product.19Wikipedia. Cross-correlation A peak marks the shift where the two line up best. To find an echo, slide a known sound clip along a recording and compute the dot product at each shift. The biggest value shows where the clip occurs.

In relativity, the metric is the dot product generalized from space to spacetime, measuring lengths and angles.20math.ucr.edu. What Does a Dot Product Represent, Exactly? On curved surfaces the dot product is defined locally at each point.21Profound Physics. The Metric Tensor: A Complete Guide With Examples