Dot or cross: which one you want
Two vector products get taught side by side and confused ever after, so here is the split in one sentence each. The dot product answers "how aligned are these two vectors" and returns one number; it works in any dimension, and it is what this page computes. The cross product answers "what direction is perpendicular to both" and returns a whole vector, and it only exists in 3D. If the perpendicular direction is what you came for, the cross product calculator is the page you want.
How the dot product works
Line the two vectors up, multiply matching components, and add the products. That is the entire recipe, and it compresses everything about how two vectors relate directionally into a single number: large and positive when they pull the same way, zero when they are perpendicular, negative when they oppose each other.
The reason one humble sum can say all that is the second identity below: the dot product equals the product of the two lengths times the cosine of the angle between them. Divide the two lengths away and you are left holding the cosine itself, which is where the angle and the cosine similarity on this page both come from.
The formula
a · b = |a| × |b| × cos θ
Here a1 and b1 are the first components of each vector, |a| and |b| are the magnitudes (the straight-line lengths, from the square root of each vector dotted with itself), and θ is the angle between the two vectors. The first line is how you compute it; the second is what it means.
Worked example
a = (2, 3) and b = (4, 1).
a · b = (2)(4) + (3)(1) = 8 + 3 = 11
|a| = √(4 + 9) = √13 = 3.605551
|b| = √(16 + 1) = √17 = 4.123106
cos θ = 11 ÷ (3.605551 × 4.123106) = 0.739940, so θ = 42.27 degrees (0.7378 radians).
That 0.739940 is also the cosine similarity of the two vectors: fairly aligned, well short of parallel.
The scaling trap
Here is the mistake that bites everyone who dots raw data instead of geometry homework. Take two houses as vectors of price in dollars, size in square meters, and bedrooms: a = (300000, 150, 3) and b = (450000, 200, 4).
The raw dot product is 135,000,030,012. Of that, the price term alone is 135,000,000,000. The size term added 30,000, and the bedrooms contributed twelve. Whatever this number measures, it is not the similarity of two houses; it is the price column talking to itself with two other columns whispering underneath.
Nothing went wrong with the arithmetic. The trap is units: dollars run five orders of magnitude larger than bedrooms, so the biggest-unit feature silently becomes the whole answer. The fix is to normalize before you compare, either by scaling each feature to a common range or by using cosine similarity, which divides the magnitudes away. Run these two houses through this page and the cosine similarity comes back as 1.0000 to four decimals, an angle of about 0.003 degrees, which is the same lesson from the other side: once direction is all that counts, two houses whose numbers are each about 1.5 times the other's point almost exactly the same way.
Cosine similarity: one number, two names
Divide the dot product by both magnitudes and you get the cosine of the angle between the vectors. A geometry classroom calls that the cosine of θ. A machine learning course calls it cosine similarity and uses it to compare embeddings, the long vectors a model assigns to words, sentences and images. It is the same number wearing two name tags, and this page prints it under both.
| Cosine similarity | Reading |
|---|---|
| 1 | Same direction exactly |
| 0.7 to 1 | Strongly aligned |
| Near 0 | Roughly unrelated directions |
| -0.7 to -1 | Strongly opposed |
| -1 | Opposite direction exactly |
One honest caveat about that table: the endpoints are mathematics, but the bands between them are conventions, not universal rules. What counts as "similar enough" depends entirely on the data. Text embeddings from some models rarely dip below 0.5 for any pair of sentences, so a 0.7 there means much less than a 0.7 between hand-built feature vectors. Calibrate against your own data before trusting a cutoff.
Zero means perpendicular
When the dot product of two nonzero vectors is exactly zero, the vectors are perpendicular: the cosine of 90 degrees is zero and nothing else in the formula can rescue it. The converse is the practical tool: to test whether two directions are at right angles, dot them and look for zero. No protractor, no trigonometry, just multiply and add. This page uses that same test on itself, showing that the leftover after a projection is perpendicular to the vector you projected onto.
Three norms, three ways to measure a vector
The magnitude used above is the L2 norm, but it has two siblings worth knowing, and this page reports all three for each vector you enter.
- L1 sums the absolute values of the components, like walking city blocks where you cannot cut the corner.
- L2 is the straight-line length of the arrow, the square root of the sum of squares.
- L-infinity is simply the single biggest component, ignoring the rest.
In machine learning these are working tools, one plain job each: L1 and L2 measure error (mean absolute error against mean squared error) and drive the two classic regularizations, where an L1 penalty pushes small weights all the way to zero and an L2 penalty shrinks everything a little. L-infinity bounds the worst single case, which is what you care about when one bad component is one too many.
Where the dot product does physical work
The word "work" in physics is a dot product wearing overalls: work equals force times distance times the cosine of the angle between them, which is exactly force dotted with displacement. Pull a sled with a rope angled 60 degrees above the ground and only half your force (cos 60 = 0.5) moves the sled forward; the rest tugs it upward and does no work along the ground. The projection this page computes is that decomposition made explicit. For the force side of that calculation, the force calculator is next door.