The angle between two vectors is one of the most fundamental calculations in linear algebra, physics, and computer graphics. Whether you are checking whether two forces are perpendicular, computing the diffuse lighting term in a shader, analysing the angle of attack on an aerofoil, or verifying that two molecule bonds meet at the correct geometry, the formula is the same: take the dot product, divide by the product of the magnitudes, and apply arccos.
This calculator handles 2-D, 3-D, and 4-D vectors. Enter the components of each vector as comma-separated numbers and you get the angle in both degrees and radians, the cosine, the dot product, magnitudes, and a complete step-by-step derivation. For 2-D inputs the calculator also shows the signed angle (positive = counter-clockwise from A to B, negative = clockwise), which the plain arccos formula cannot distinguish. For 3-D inputs it adds the cross product A × B and its magnitude, which equals |A||B|sinθ — handy for finding the normal to a plane or the torque arm.
How it works
Given vectors A = (a₁, a₂, …) and B = (b₁, b₂, …) of the same dimension n:
cos θ = (A · B) / (|A| |B|)
where the dot product A · B = ∑ aᵢ bᵢ and the magnitudes |A| = √(∑ aᵢ²), |B| = √(∑ bᵢ²). The angle θ is then:
θ = arccos( A · B / (|A| |B|) )
The calculator clamps the cosine to the interval [-1, 1] before calling arccos so that tiny floating-point rounding errors (e.g. a value of 1.0000000002 from perfect parallel vectors) do not produce a NaN. The result is always in [0, π] (i.e. 0° to 180°).
2-D signed angle
For 2-D vectors the signed angle from A to B is computed via atan2(cross, dot) where cross = a₁b₂ - a₂b₁ (the z-component of the 3-D cross product). This returns a value in (-180°, 180°]: positive if B is counter-clockwise from A, negative if clockwise.
3-D cross product
For 3-D vectors the cross product A × B is:
(a₂b₃ - a₃b₂, a₃b₁ - a₁b₃, a₁b₂ - a₂b₁)
Its magnitude |A × B| = |A| |B| sin θ provides an independent check on the angle. When the cross product is the zero vector the two vectors are parallel (or anti-parallel).
Vector projections
The vector projection of A onto B is proj_B(A) = (A · B / |B|²) B. It is the portion of A that points in the direction of B. The scalar projection is A · B / |B|.
Worked example
Find the angle between A = (1, 2, 2) and B = (2, 1, -2).
- |A| = √(1 + 4 + 4) = √9 = 3
- |B| = √(4 + 1 + 4) = √9 = 3
- A · B = (1)(2) + (2)(1) + (2)(-2) = 2 + 2 - 4 = 0
- cos θ = 0 / (3 × 3) = 0
- θ = arccos(0) = 90° (the vectors are perpendicular)
Cross product: A × B = (2·(-2) - 2·1, 2·2 - 1·(-2), 1·1 - 2·2) = (-6, 6, -3). |A × B| = √(36+36+9) = √81 = 9, and |A||B|sin(90°) = 3·3·1 = 9. The two routes agree.
| A | B | Angle |
|---|---|---|
| (1, 0) | (0, 1) | 90° |
| (1, 1) | (1, 0) | 45° |
| (1, 0, 0) | (0, 1, 0) | 90° |
| (1, 2, 2) | (2, 1, -2) | 90° |
| (1, 0, 0) | (-1, 0, 0) | 180° |
Everything is calculated live in your browser. No data leaves your device.