Skip to content
Formulaxis

Toolbox

Dot product: calculating the angle between two vectors

Determine the angle between two nonzero vectors in 2D or 3D. The calculation also gives their dot product, magnitudes and the cosine of the angle, which lies between 0° and 180° without a direction of rotation.

Created on , Revised on v2.0

Method and validation

Dot product: calculating the angle between two vectors

dimensionless

Signed component of u on the x-axis, in the orthonormal coordinate system shared by the vectors.

dimensionless

Signed component of u on the y-axis, in the orthonormal coordinate system shared by the vectors.

dimensionless

Signed component of v on the x-axis, in the orthonormal coordinate system shared by the vectors.

dimensionless

Signed component of v on the y-axis, in the orthonormal coordinate system shared by the vectors.

Initial values are examples.

Results

Dot product u·v
0dimensionless
Magnitude of u Nu
5dimensionless
Magnitude of v Nv
5dimensionless
Cosine of the angle cos θ
0dimensionless
Unsigned angle θ
90°

Substitution in SI units

u·v=3×4+4×(−3)=0

Both vectors must be nonzero in this combined calculation.

The unsigned angle between u and v

Dot product: calculating the angle between two vectors · Two vectors in 2DOrthonormal coordinate system; directions and length ratios follow the entered components.xyu = (3 ; 4)v = (4 ; -3)θ = 90 ° · u·v = 0

Orthonormal coordinate system; directions and length ratios follow the entered components.

Illustrative diagram, not to scale.

Estimated reading time : 5 min · 868 words

Calculation details

The sign of the dot product indicates the angle: positive below 90°, zero at 90°, negative above it. The resulting angle is unoriented and gives no direction of rotation.

01 · Dot product

FORMULA

u·v=ux×vx+uy×vy

NUMERICAL SUBSTITUTION

u·v=3×4+4×(−3)

RESULT

u·v=0

02 · Magnitude of u

FORMULA

Nu=ux2+uy2

NUMERICAL SUBSTITUTION

Nu=32+42

RESULT

Nu=5

03 · Magnitude of v

FORMULA

Nv=vx2+vy2

NUMERICAL SUBSTITUTION

Nv=42+(−3)2

RESULT

Nv=5

04 · Cosine of the angle

FORMULA

cos(θ)=min(1,max(−1,ux×vx+uy×vyux2+uy2×vx2+vy2))

NUMERICAL SUBSTITUTION

cos(θ)=min(1,max(−1,3×4+4×(−3)32+42×42+(−3)2))

RESULT

cos(θ)=0

05 · Unsigned angle

FORMULA

θ=acos(min(1,max(−1,ux×vx+uy×vyux2+uy2×vx2+vy2)))

NUMERICAL SUBSTITUTION

θ=acos(min(1,max(−1,3×4+4×(−3)32+42×42+(−3)2)))

RESULT

θ=90 °

From the dot product to the angle between vectors

The dot product sums the products of corresponding components. It relates the magnitudes to the angle between the two vectors and returns a number. For nonzero vectors, its sign distinguishes an acute, right or obtuse angle. The calculated angle does not describe any direction of rotation: it remains between 0 and 180 degrees.

Formulas and symbols

The following relationships use the symbols defined below.

u·v=ux×vx+uy×vy(dot product)

Nu=ux2+uy2(magnitude of u)

Nv=vx2+vy2(magnitude of v)

cos(θ)=min(1,max(−1,ux×vx+uy×vyux2+uy2×vx2+vy2))(cosine of the angle)

θ=acos(min(1,max(−1,ux×vx+uy×vyux2+uy2×vx2+vy2)))(unsigned angle)

u·v=ux×vx+uy×vy+uz×vz(dot product)

Nu=ux2+uy2+uz2(magnitude of u)

Nv=vx2+vy2+vz2(magnitude of v)

cos(θ)=min(1,max(−1,ux×vx+uy×vy+uz×vzux2+uy2+uz2×vx2+vy2+vz2))(cosine of the angle)

θ=acos(min(1,max(−1,ux×vx+uy×vy+uz×vzux2+uy2+uz2×vx2+vy2+vz2)))(unsigned angle)

  • u and v: unitless vectors in the same orthonormal coordinate system.
  • ux, uy, uz and vx, vy, vz: components.
  • ‖u‖ and ‖v‖: magnitudes.
  • u·v: dot product.
  • θ: unoriented angle. The ratio of the dot product to the product of the magnitudes is numerically clamped between −1 and 1 before arccos to prevent rounding from pushing it outside this range.

Sign and angle for nonzero vectors

Dot productAngleInterpretation
PositiveFrom 0° inclusive to 90° exclusiveAcute angle or identical directions
Zero90°Orthogonality
NegativeFrom 90° exclusive to 180° inclusiveObtuse angle or opposite directions
+‖u‖‖v‖0°Same direction and sense
−‖u‖‖v‖180°Same line, opposite senses

OpenStax — dot product and angle ; Wolfram MathWorld — Dot Product.

Worked examples

Example 1: Two orthogonal vectors in 2D

For u = (3 ; 4) and v = (4 ; −3), the dot product is 12 − 12, or 0. Both magnitudes are 5 and the angle is 90°.

Example 2: Two vectors in space

For u = (1 ; 2 ; 2) and v = (2 ; 0 ; 1), the dot product is 4. The magnitudes are 3 and 5; the cosine is about 0,596285 and the angle about 53,40°.

Example 3: Two vectors pointing in opposite directions

For (1 ; 0) and (−2 ; 0), the dot product is −2, the cosine is −1 and the angle is 180°.

Assumptions and limitations

Both vectors must be nonzero in this combined calculation. The dot product with a zero vector is indeed zero, but the angle would be undefined, so such inputs are rejected here. Orthonormal coordinate system and unitless components. This page does not calculate oriented angles, vector projections or forces.

Common mistakes

Do not add the magnitudes in the denominator: multiply them. The angles 0° and 180° describe collinear vectors pointing, respectively, in the same and opposite senses. A zero dot product indicates orthogonality only after zero vectors have been excluded.

Frequently asked questions

What does a negative dot product mean?

For two nonzero vectors, their unoriented angle exceeds 90°. If the cosine is −1, the vectors point in opposite senses along the same direction.

Why is the angle with the zero vector undefined?

The zero vector has no direction, and its magnitude makes the denominator in the angle formula zero. Even though its dot product with any vector is zero, this combined calculation rejects a zero vector to avoid assigning it an angle.

Is the dot product a projection length?

Divide the dot product by the target vector’s norm to obtain a signed scalar projection. Its absolute value is a length.

Does scaling change the angle?

Positive scaling preserves the angle. Negative scaling reverses one vector and gives the supplementary angle; zero makes the angle undefined.