Dot Product Calculator
Enter the components of two vectors in 2D or 3D to get the dot product, the magnitudes, the angle between them, the scalar and vector projections, and whether the vectors are orthogonal. Switch to Magnitudes + Angle mode to reverse-solve for the dot product from two lengths and an angle.
Formula
Worked example
For a = (1, 2, 3) and b = (4, -5, 6): a·b = 1·4 + 2·(-5) + 3·6 = 4 - 10 + 18 = 12. The magnitudes are |a| = sqrt(1+4+9) = sqrt(14) approx 3.7417 and |b| = sqrt(16+25+36) = sqrt(77) approx 8.7749. So cosθ = 12 / (3.7417 × 8.7749) approx 0.3655, giving θ = arccos(0.3655) approx 68.56°. The scalar projection of a onto b is 12 / 8.7749 approx 1.3677, and the vector projection is (1.3677 / 8.7749) × (4, -5, 6) = (0.6234, -0.7792, 0.9350).
What the dot product measures
The dot product, also called the scalar product or inner product, takes two vectors and returns a single number rather than another vector. In component form you multiply matching coordinates and add the results: a·b = aₓbₓ + a_yb_y (in 2D) or a·b = aₓbₓ + a_yb_y + a_zb_z (in 3D). The geometric interpretation is a·b = |a||b|cosθ: the product of the two magnitudes times the cosine of the angle between them. This makes the dot product a direct measure of alignment. It is largest when the vectors point the same way, exactly zero when they are perpendicular, and negative when the angle between them exceeds 90°. Because cosθ is bounded between -1 and 1, the sign of the dot product alone tells you whether the angle is acute, right, or obtuse without computing the angle itself. The dot product is commutative (a·b = b·a) and distributive over addition, which makes it useful in linear algebra, physics, and machine learning.
Finding the angle between two vectors
Rearranging a·b = |a||b|cosθ gives cosθ = (a·b)/(|a||b|), and taking the inverse cosine (arccos) returns θ in the range 0° to 180°. The magnitudes come from the Pythagorean theorem extended to three dimensions: |a| = sqrt(aₓ² + a_y² + a_z²). A practical caution is that floating-point rounding can push the ratio fractionally beyond +1 or -1, making arccos undefined; this calculator clamps the value to the valid range before applying arccos. If either vector is the zero vector, the angle is undefined and only the dot product is reported. For the reverse problem: if you know both magnitudes and the angle, switch to Magnitudes + Angle mode and the calculator applies a·b = |a||b|cosθ directly.
Scalar and vector projections
The scalar projection of a onto b (also written comp_b(a)) is the signed length of a's shadow cast onto the line of b: comp_b(a) = a·b / |b|. It is positive when the projection points in the same direction as b, and negative when it points opposite. The vector projection, proj_b(a), is the actual vector along b with that length: proj_b(a) = (a·b / |b|²) × b. These are essential for decomposing forces in physics (the component of a force along a direction), computing work done by a non-parallel force, and orthogonalising a set of vectors using the Gram-Schmidt process. Scalar projections in 2D and 3D are available in this calculator alongside the dot product and angle.
Orthogonality, physics and machine learning applications
Two non-zero vectors are orthogonal (perpendicular) if and only if their dot product is zero. This is the standard algebraic test for right angles and is used everywhere from checking if two lines are perpendicular in geometry, to verifying that principal components in PCA are uncorrelated, to confirming that a basis set is orthonormal in quantum mechanics. In physics, the dot product computes the work done by a force F over a displacement d: W = F·d, which is why a force perpendicular to motion does no work (F·d = 0). In machine learning, cosine similarity between two vectors is directly related to the dot product: cosine_similarity(a, b) = a·b / (|a||b|), and the dot product of two unit vectors is their cosine similarity. The dot product also underlies attention mechanisms in transformer models.
Dot product sign, angle, and projection summary
| Dot product a·b | cos θ range | Angle θ | Relationship | Projection of a onto b |
|---|---|---|---|---|
| a·b = |a||b| | 1 | 0° | Parallel (same direction) | Full length of a |
| a·b > 0 | 0 to 1 | 0° to 90° | Acute | Positive (same side as b) |
| a·b = 0 | 0 | 90° | Perpendicular (orthogonal) | Zero |
| a·b < 0 | -1 to 0 | 90° to 180° | Obtuse | Negative (opposite side) |
| a·b = -|a||b| | -1 | 180° | Anti-parallel (opposite direction) | Negative full length |
A quick reference for interpreting the dot product of two non-zero vectors a and b.
Frequently asked questions
What does a dot product of zero mean?
A dot product of zero means the two vectors are perpendicular (orthogonal), meeting at exactly 90°. Because a·b = |a||b|cosθ and cos(90°) = 0, the product is zero whenever the angle is a right angle, as long as neither vector is the zero vector. Testing for a zero dot product is the standard algebraic way to verify orthogonality, used everywhere from geometry to principal component analysis.
How do I calculate the dot product in 2D?
For 2D vectors a = (aₓ, a_y) and b = (bₓ, b_y), the dot product is simply aₓbₓ + a_yb_y. Select "2D" in the Dimensions menu and enter only the x and y components; the calculator ignores the z terms. Everything else, including the angle and projections, is computed using the 2D formula sqrt(aₓ² + a_y²) for the magnitudes.
Can the dot product be negative?
Yes. The dot product is negative whenever the angle between the vectors is greater than 90° (obtuse), because cosθ is negative for angles in that range. A negative value tells you the vectors point in generally opposing directions. The most negative possible dot product is -|a||b|, reached when the vectors are exactly anti-parallel at 180°.
What is the scalar projection and how is it different from the dot product?
The scalar projection of a onto b, written comp_b(a), is a·b divided by |b|. It gives the signed length of a's shadow on the line of b, with units matching the vector components. The dot product itself is a·b = |a||b|cosθ, which has units of length squared. The scalar projection is effectively the component of a in the direction of b, and equals |a|cosθ.
How is the dot product different from the cross product?
The dot product returns a single number (a scalar) and measures how aligned two vectors are. The cross product returns a new vector perpendicular to both inputs, with magnitude |a||b|sinθ that measures how perpendicular they are. Use the dot product for projections, angles, work, and similarity. Use the cross product for areas, torque, surface normals, and finding a vector perpendicular to two given vectors.
How do I find the dot product from magnitudes and an angle?
Switch to Magnitudes + Angle mode, then enter |a|, |b|, and the angle θ in degrees. The calculator applies the formula a·b = |a||b|cosθ directly. This is the reverse-solve workflow: useful when you know the lengths of two vectors and the angle between them but do not have the individual components.