Vector Dot Product and Angle Calculator

Enter two vectors in two or three dimensions and this calculator returns their dot product, each vector's length, the cosine of the angle between them, that angle in degrees and radians, and the projection of the first vector onto the second. The dot product is the standard test for perpendicularity — it is zero exactly when two vectors meet at a right angle — and its normalised form, the cosine, is the similarity measure used throughout search, recommendation and machine learning. The table also splits the first vector into the part along the second and the part at right angles to it.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
DimensionsChoose 2D to hide the z fields; they are then treated as zero, which gives the same answers as entering 0.3D — x, y and z
a: x componentThe x component of the first vector.2
a: y componentThe y component of the first vector.3
a: z componentThe z component of the first vector.6
b: x componentThe x component of the second vector.1
b: y componentThe y component of the second vector.2
b: z componentThe z component of the second vector. Projection is taken of a onto b, so this field decides the direction projected onto.2

It returns

  • Dot product a · b — The sum of the componentwise products. Zero means the two vectors are perpendicular.
  • cos θ (cosine similarity) — The dot product divided by the two lengths, always between −1 and 1.
  • Angle between a and b — Reported in [0°, 180°]; the dot product cannot distinguish clockwise from anticlockwise.
  • Angle in radians
  • Length |a|
  • Length |b|
  • Scalar projection of a onto b — (a · b) ÷ |b| — how far a reaches along the direction of b. Negative when the angle exceeds 90°.

The formula

cosθ=ab|a||b|
projba=ab|b|2b
|a×b|2+(ab)2=|a|2|b|2

In plain text: a · b = aₓbₓ + a_yb_y + a_zb_z = |a||b| cos θ, so θ = arccos(a·b ÷ (|a||b|))

  • a · bDot product — a single number, not a vector (product of a and b units)
  • |a|, |b|Lengths of the two vectors, √(x² + y² + z²) (same as the components)
  • θAngle between the vectors, in [0°, 180°] (degrees)
  • compᵦaScalar projection of a onto b, (a·b) ÷ |b| (same as a)
  • projᵦaVector projection of a onto b, ((a·b) ÷ |b|²) b (same as a)

The algebraic definition (sum of componentwise products) and the geometric definition (|a||b| cos θ) are equal; that equivalence follows from the law of cosines applied to the triangle formed by a, b and a − b.

Updated Category Matrices, Vectors & Complex Numbers Verified against published test cases Reading time 12 min

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 ab. The law of cosines says |ab|² = |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.

  1. Componentwise products. 2 × 1 = 2, 3 × 2 = 6, 6 × 2 = 12.
  2. Dot product. 2 + 6 + 12 = 20.
  3. Length of a. √(4 + 9 + 36) = √49 = 7.
  4. Length of b. √(1 + 4 + 4) = √9 = 3.
  5. Cosine. 20 ÷ (7 × 3) = 20 ÷ 21 = 0.9523810.
  6. Angle. arccos(0.9523810) = 17.753°, which is 0.309845 radians.
  7. Scalar projection. 20 ÷ 3 = 6.6666667. Since |a| = 7, almost all of a's length lies along b — consistent with an angle under 18°.
  8. 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).
  9. 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 axbyaybx, 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

Every row uses |a| = 5 and |b| = 4, so |a||b| = 20. The dot product is 20 cos θ and the scalar projection of a onto b is 5 cos θ.
Angle θcos θa · bScalar projectionRelationship
1.00000020.0000005.000000same direction
30°0.86602517.3205084.330127acute
45°0.70710714.1421363.535534acute
60°0.50000010.0000002.500000acute
90°0.0000000.0000000.000000perpendicular
120°−0.500000−10.000000−2.500000obtuse
135°−0.707107−14.142136−3.535534obtuse
150°−0.866025−17.320508−4.330127obtuse
180°−1.000000−20.000000−5.000000opposite 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].

Frequently asked questions

How do I find the angle between two vectors?

Divide the dot product by the product of the two lengths and take the arccosine. For (2,3,6) and (1,2,2), the dot product is 20 and the lengths are 7 and 3, so cos θ = 20 ÷ 21 = 0.952381 and θ = 17.753°. The result always lands between 0° and 180°. If you need to know which way round the turn goes, the dot product cannot tell you — use a cross product for that.

What does a negative dot product mean?

That the angle between the vectors is greater than 90°, so they point into opposite half-spaces. The scalar projection is then negative too, meaning the first vector reaches backwards along the second. In mechanics this is exactly how a braking force shows up: the force and the displacement have a negative dot product, so the work done is negative and energy leaves the body.

How do I check whether two vectors are perpendicular?

Compute the dot product and see whether it is zero. (3,4) and (−4,3) give −12 + 12 = 0, so they are perpendicular. This is much better than computing the angle and comparing with 90°, because the dot product needs no square roots and no arccos, so it introduces far less rounding error. With floating-point inputs, test against a small multiple of |a||b| rather than against exact zero.

What is the difference between the dot product and the cross product?

The dot product returns a number and is largest when the vectors are aligned; the cross product returns a vector and is largest when they are perpendicular. The dot product exists in any number of dimensions, while the cross product is specific to three. Use the dot product for angles, projections and perpendicularity tests, and the cross product for normals, areas and torque.

Is cosine similarity the same as the dot product?

Not quite — cosine similarity is the dot product after both vectors have been divided by their lengths. That removes magnitude and leaves direction, which is why it sits between −1 and 1 regardless of the scale of the data. If your vectors are already unit length, the two are identical, which is why embedding libraries normalise once up front and then use a plain dot product for speed.

Can the dot product be larger than the product of the lengths?

No. The Cauchy–Schwarz inequality guarantees |a·b| ≤ |a||b|, with equality only when the two vectors are collinear. That is precisely what keeps cos θ inside [−1, 1] so the arccosine is always defined. If a computation ever produces a cosine slightly outside that range, it is floating-point error, and the correct fix is to clamp before calling arccos — which this calculator does.

How do I project one vector onto another?

Multiply b by the scale factor (a·b) ÷ |b|². For a = (2,3,6) and b = (1,2,2), that factor is 20 ÷ 9 = 2.222222, so the projection is (2.222222, 4.444444, 4.444444). Subtracting it from a leaves (−0.222222, −1.444444, 1.555556), which is perpendicular to b. The table on this page shows both pieces, and they add back to a exactly.

Does this work for vectors with more than three components?

The mathematics does, and the definition is the same sum of componentwise products, but this page is limited to two and three dimensions. Everything on it generalises unchanged: lengths are still square roots of sums of squares, cos θ is still the dot product over the two lengths, and Cauchy–Schwarz still holds. That is exactly why cosine similarity works on 768-dimensional embeddings.

Why does the angle output vanish when I enter a zero vector?

Because a zero vector has no direction, so there is no angle to report. The dot product is still defined and equals zero, but dividing by |b| = 0 to get the cosine is not, so the cosine, the angle and the projection are all left blank. Reporting 90° there would be wrong: perpendicularity is a statement about two directions, and one of them does not exist.

References

  • Introduction to Linear Algebra, 5th ed. (Chapter 1, dot products and lengths) — Gilbert Strang, Wellesley-Cambridge Press
  • Linear Algebra Done Right, 4th ed. (Chapter 6, Inner Product Spaces) — Sheldon Axler, Springer
  • NIST Digital Library of Mathematical Functions, §4.14 Trigonometric IdentitiesNational Institute of Standards and Technology
  • Introduction to Information Retrieval (Chapter 6, vector space scoring and cosine similarity) — Christopher D. Manning, Prabhakar Raghavan and Hinrich Schütze, Cambridge University Press