Dot Product Calculator

Dot product
Next

The dot product collapses two vectors into a single scalar that encodes how much they point in the same direction. It powers cosine similarity for search ranking, projection for physics, and every lighting calculation in computer graphics. This tool computes a dot product for two vectors of matching dimension (2D, 3D, N-D) and shows the cosine of the angle between them.

How to compute a dot product

  1. 1

    Enter both vectors

    Type components separated by commas or spaces: `3, 4, 5` for one vector and `1, 2, 1` for the other.

  2. 2

    Match dimensions

    The vectors must have the same length. The tool flags mismatches before calculating.

  3. 3

    See the result

    The scalar dot product is shown together with the cosine of the angle (cos θ) and the angle itself in degrees.

The two formulas

Component form for vectors a = (a1, a2, ..., an) and b = (b1, b2, ..., bn):

a . b = a1*b1 + a2*b2 + ... + an*bn

Geometric form:

a . b = |a| * |b| * cos(theta)

The two expressions are equal; setting them equal gives you cos(theta) = (a.b) / (|a| |b|), the cosine similarity formula.

What the sign tells you

Dot product Meaning
Positive Vectors point roughly the same direction (angle < 90)
Zero Vectors are orthogonal (perpendicular)
Negative Vectors point roughly opposite directions (angle > 90)

Worked example

a = (3, 4), b = (1, 2):

  • Components: 31 + 42 = 3 + 8 = 11
  • |a| = sqrt(9 + 16) = 5
  • |b| = sqrt(1 + 4) = sqrt(5) ~ 2.236
  • cos(theta) = 11 / (5 * 2.236) = 0.9839
  • theta = arccos(0.9839) ~ 10.3 degrees

The vectors point almost the same way, hence the large positive dot product.

Common applications

  • Cosine similarity for recommender systems: how similar are two embedding vectors?
  • Projection of one vector onto another: proj_b(a) = (a . b) / |b|^2 * b.
  • Work in physics: W = F . d, force dotted with displacement.
  • Graphics lighting: surface normal dotted with light direction gives diffuse brightness (Lambert’s law).
  • Orthogonality check: quickly verify whether two basis vectors are perpendicular.

Tips

  • Normalize before comparing. If you only care about direction (similarity), divide each vector by its magnitude first; then the dot product equals the cosine directly.
  • Watch the dimension. A 3-vector dotted with a 4-vector is undefined; pad or truncate deliberately, not accidentally.
  • Numerical stability. For very large vectors, floating-point accumulation can lose precision; use double precision or Kahan summation when dimension exceeds a few thousand.

Frequently Asked Questions

Dot product returns a scalar, measures “how parallel” two vectors are. Cross product (defined only in 3D and 7D) returns a vector perpendicular to both, measures “how perpendicular”. They answer opposite questions.

Yes, for any dimension N. The component-wise definition extends directly; it is used every day in machine learning with vectors of hundreds or thousands of dimensions.

Because the geometric form |a| |b| cos(theta) is zero when cos is zero, which happens at 90 and 270 degrees. Two non-zero vectors are orthogonal precisely when their dot product is zero.

The vector components you enter are sent to our server because the calculation runs there. They are not stored or linked to your account.

Related Tools

Tool available in other languages