What the dot product measures
The dot product takes two vectors and returns a single number that says how much they point the same way. Multiply matching components and add: (2, 3, 6)·(1, 2, 2) = 2 + 6 + 12 = 20. That number is largest when the vectors are aligned, zero when they are perpendicular, and negative when they point into opposite half-spaces. It is also called the scalar product, because the answer is a scalar, and the inner product, which is the name used when the idea is generalised beyond ordinary Euclidean space.
The reason it is useful is that the same number has a purely geometric description: a·b = |a||b| cos θ. One formula is easy to compute from coordinates and the other is easy to reason about, and their equality is what lets you extract an angle from raw numbers without any trigonometry on the input side. Rearranged, cos θ = a·b ÷ (|a||b|), and that is exactly what this calculator does.
The zero test is the workhorse. Two non-zero vectors are perpendicular if and only if their dot product is zero, and checking that costs three multiplications and two additions with no square roots and no arccos. Collision detection, plane equations, back-face culling and Gram–Schmidt orthogonalisation all lean on it. Where you need a perpendicular vector rather than a perpendicularity test, that is the cross product instead.
Why the two definitions agree, and what projection means
Start with the triangle whose sides are a, b and a − b. The law of cosines says |a − b|² = |a|² + |b|² − 2|a||b| cos θ. Now expand the left side in coordinates: it comes out as |a|² + |b|² − 2(axbx + ayby + azbz). Cancel the common terms and divide by −2, and the componentwise sum is forced to equal |a||b| cos θ. Nothing else could work.
Scalar projection answers “how far does a reach along the direction of b?” Drop a perpendicular from the tip of a onto the line through b; the signed length from the origin to that foot is |a| cos θ, which equals a·b ÷ |b|. Note that it depends on the direction of b but not on its length, since dividing by |b| cancels the scale.
Vector projection puts that length back onto the direction: projba = (a·b ÷ |b|²) b. Subtracting it from a leaves the perpendicular part, and those two pieces reconstruct a exactly. This orthogonal decomposition is the single most reused idea in linear algebra: it is how least-squares regression finds the closest point in a subspace, how Gram–Schmidt builds an orthonormal basis, and how a reflection off a surface is computed in graphics.
Cosine similarity is the projection idea with both lengths divided out. Because cos θ lies in [−1, 1] regardless of scale, it compares direction alone, which is why documents represented as long word-count vectors are compared by cosine rather than by distance — a document twice as long should not count as a different topic.
Worked example: (2, 3, 6) · (1, 2, 2)
These are the calculator's defaults, chosen because both lengths come out whole.
- Componentwise products. 2 × 1 = 2, 3 × 2 = 6, 6 × 2 = 12.
- Dot product. 2 + 6 + 12 = 20.
- Length of a. √(4 + 9 + 36) = √49 = 7.
- Length of b. √(1 + 4 + 4) = √9 = 3.
- Cosine. 20 ÷ (7 × 3) = 20 ÷ 21 = 0.9523810.
- Angle. arccos(0.9523810) = 17.753°, which is 0.309845 radians.
- Scalar projection. 20 ÷ 3 = 6.6666667. Since |a| = 7, almost all of a's length lies along b — consistent with an angle under 18°.
- Vector projection. The scale factor is a·b ÷ |b|² = 20 ÷ 9 = 2.2222222, so projba = 2.2222222 × (1, 2, 2) = (2.222222, 4.444444, 4.444444).
- Perpendicular part. a − projba = (2 − 2.222222, 3 − 4.444444, 6 − 4.444444) = (−0.222222, −1.444444, 1.555556).
Two checks. First, the perpendicular part must have zero dot product with b: (−0.222222)(1) + (−1.444444)(2) + (1.555556)(2) = −0.222222 − 2.888889 + 3.111111 = 0. Second, its length must equal |a| sin θ. Its length is √(0.049383 + 2.086420 + 2.419753) = √4.555556 = 2.134375, and sin θ = √(1 − 400/441) = √41 ÷ 21 = 0.3049107, so 7 × 0.3049107 = 2.134375. Both hold.
How to read the sign, the cosine and the projection
The sign is the fastest thing to read. A positive dot product means the angle is under 90°; zero means exactly 90°; negative means over 90°. In graphics this single test decides whether a surface faces the camera. In physics it decides whether a force does positive or negative work, since work is F·d — a braking force opposing motion gives a negative number, which is exactly right for energy removed.
The cosine is scale-free, the dot product is not. Doubling either vector doubles the dot product but leaves the cosine and the angle untouched. If you are comparing directions, read the cosine; if you are computing work, flux or a weighted sum, read the dot product. This is the usual source of confusion when people ask why two “very similar” vectors have a small dot product: they had small lengths.
The angle is unsigned. arccos returns a value in [0°, 180°], so the dot product cannot tell you whether b is clockwise or anticlockwise from a. If you need that, use the sign of the 2D cross product axby − aybx, or in 3D the direction of the full cross product.
A zero dot product is not always perpendicularity. If either vector is the zero vector, the dot product is zero because everything is multiplied by nothing, and the angle is genuinely undefined rather than 90°. This calculator leaves the angle and cosine blank in that case rather than reporting a right angle that does not exist.
Precision near 0° and 180°. arccos is flat near cos θ = ±1, so a rounding error of 10−8 in the cosine can move the reported angle by about 0.008° there, while the same error near 90° moves it by roughly 6 × 10−7 degrees. When you need a tiny angle accurately, work from the cross-product magnitude instead, because sine is steep exactly where cosine is flat.
Dot product and projection across the range of angles
| Angle θ | cos θ | a · b | Scalar projection | Relationship |
|---|---|---|---|---|
| 0° | 1.000000 | 20.000000 | 5.000000 | same direction |
| 30° | 0.866025 | 17.320508 | 4.330127 | acute |
| 45° | 0.707107 | 14.142136 | 3.535534 | acute |
| 60° | 0.500000 | 10.000000 | 2.500000 | acute |
| 90° | 0.000000 | 0.000000 | 0.000000 | perpendicular |
| 120° | −0.500000 | −10.000000 | −2.500000 | obtuse |
| 135° | −0.707107 | −14.142136 | −3.535534 | obtuse |
| 150° | −0.866025 | −17.320508 | −4.330127 | obtuse |
| 180° | −1.000000 | −20.000000 | −5.000000 | opposite directions |
The scalar-projection column is the dot-product column divided by |b| = 4 in every row, and it never exceeds |a| = 5 in size — that bound is the Cauchy–Schwarz inequality, which says |a·b| ≤ |a||b| with equality only when the vectors are collinear.
Testing perpendicularity without square roots
To ask whether two vectors are at right angles, compute the dot product and compare it with zero. Do not compute the angle and compare with 90°: that route takes two square roots and an arccos, all of which introduce rounding error, and it can report 89.9999998° for a pair that are exactly perpendicular in exact arithmetic. With floating-point components that came from earlier calculations, test |a·b| < ε|a||b| for a small relative tolerance rather than comparing against a bare zero — an absolute threshold behaves completely differently for vectors of length 0.001 and vectors of length 1,000.
Mistakes and assumptions
- Expecting a vector back. The dot product is a single number. If you wanted a perpendicular vector, you wanted the cross product.
- Confusing scalar and vector projection. The scalar projection (a·b) ÷ |b| is a signed length; the vector projection multiplies it by the unit vector along b. Using one where the other belongs gives an answer wrong by a factor of |b|.
- Projecting onto the wrong vector. projba and projab are different vectors pointing in different directions. This page projects a onto b, so the b fields set the direction.
- Reading zero as perpendicular when a vector is zero. The zero vector has no direction, so no angle exists. The calculator blanks the angle rather than reporting 90°.
- Comparing dot products of differently scaled vectors. A dot product mixes direction and magnitude. For similarity work, divide by both lengths and compare cosines instead.
- Assuming the angle is signed. arccos gives [0°, 180°] and cannot distinguish a 40° turn one way from 40° the other. Recover the sense from a cross product.
- Applying it outside a Euclidean setting. These formulas assume perpendicular axes with equal scales. In a skewed or weighted coordinate system the inner product carries a metric matrix and the plain componentwise sum is not it.
Where the dot product is used, and its relatives
Physics. Work is W = F·d, so a force at right angles to motion does no work at all — which is why a satellite in a circular orbit neither gains nor loses energy from gravity. Flux through a surface is E·A, largest when the field runs straight through the surface and zero when it grazes it. Power delivered to a moving body is F·v.
Graphics and geometry. Lambertian shading multiplies light intensity by the dot product of the surface normal with the direction to the light, clamped at zero, so faces turned away go dark. The plane through point P with normal n is the set of x with n·(x − P) = 0, and the signed distance of any point from that plane is that same dot product divided by |n|.
Data and machine learning. Cosine similarity is the dot product of two unit-normalised vectors, and it is the default similarity measure for text embeddings and recommendation systems. A neural network layer is a matrix multiplication, and every entry of the output is a dot product of an input vector with a row of weights — the matrix multiplication calculator shows that structure directly.
Related tools. Use the cross product when you need a perpendicular direction or an area; the two are complementary halves of the same information, tied together by |a × b|² + (a·b)² = |a|²|b|². Use the determinant for volumes and orientation of a whole set of vectors, and the eigenvalue calculator when the question is about a transformation's own preferred directions rather than about two given vectors. For rotation in the plane, complex multiplication packages the dot and cross products together: the real part of z̄1z2 is the dot product and the imaginary part is the 2D cross product.
Key terms
- Dot product
- The sum of componentwise products, equal to |a||b| cos θ. Also called the scalar product or the Euclidean inner product.
- Cosine similarity
- The dot product divided by both lengths. It lies in [−1, 1] and measures direction alone, ignoring magnitude.
- Scalar projection
- compba = (a·b) ÷ |b|, the signed length of a measured along the direction of b.
- Vector projection
- projba = ((a·b) ÷ |b|²) b, the part of a that lies along b. Subtracting it from a leaves the perpendicular part.
- Orthogonal
- Perpendicular, in the sense that the dot product is zero. Orthonormal adds the requirement that each vector has length 1.
- Cauchy–Schwarz inequality
- |a·b| ≤ |a||b| for all vectors, with equality exactly when they are collinear. It is what guarantees the cosine never leaves [−1, 1].
