Starlight Tools

Angle Between Two Vectors Calculator

Find the smallest enclosed angle from 0° to 180° between two nonzero vectors using the dot product. Enter 2D or 3D vectors, with 4D also supported. Use components or point pairs independently for each vector to get degrees, radians, working, and a geometric interpretation. Calculations run privately in your browser.

Vectors & settings

Results update as you type. Enter every visible coordinate; use 0 for a zero component. Scientific notation such as 1e-8 is accepted.

Try an example

Vector a
Vector b

Press Enter to calculate. Share copies a link with your inputs and display precision.

Angle between your vectors

Smallest unsigned angle—

Enter two nonzero vectors to calculate their angle.

Step-by-step working

Working appears when all inputs are valid.

2D vector diagram

A text description of the vectors and their angle appears below this diagram.

Enter valid 2D vectors to see the diagram.

Solid blue arrow: a. Dashed orange arrow: b. Vectors start at a common origin; axes have equal scales.

How to use this calculator

  1. Choose 2D, 3D, or 4D and your display precision.
  2. For each vector, independently choose Components or Two points. For point pairs, enter the initial and terminal coordinates; the vector is terminal minus initial.
  3. Enter every coordinate. Results, working, and the 2D diagram update automatically, or press Calculate.
  4. Read the angle and relationship, then use the steps to check the calculation. Load an example below to explore.

For example, a vector from (1, 2) to (4, 6) has components (4 − 1, 6 − 2) = (3, 4). In 3D and 4D, subtract the z and w coordinates in the same way.

Angle between two vectors: formula and derivation

Start with the dot-product identity for nonzero vectors:

a·b=‖a‖‖b‖cosθ

In text: a · b = ‖a‖ ‖b‖ cos θ

Divide both sides by the positive product of the magnitudes, then take the inverse cosine:

cosθ=a·b‖a‖‖b‖⇒θ=arccos(a·b‖a‖‖b‖)

In text: cos θ = (a · b)/(‖a‖ ‖b‖), so θ = arccos((a · b)/(‖a‖ ‖b‖)).

Expanded 2D formula

θ=arccos(axbx+aybyax2+ay2bx2+by2)

In text: θ = arccos((ax bx + ay by) / (√(ax² + ay²) √(bx² + by²))).

Expanded 3D formula

θ=arccos(axbx+ayby+azbzax2+ay2+az2bx2+by2+bz2)

In text: θ = arccos((ax bx + ay by + az bz) / (√(ax² + ay² + az²) √(bx² + by² + bz²))).

Symbols: a and b are vectors; aₓ, aᵧ, a_z and bₓ, bᵧ, b_z are their Cartesian components. The dot (·) means dot product, ‖a‖ and ‖b‖ mean lengths (magnitudes), θ is the enclosed angle, √ means square root, cos means cosine, and arccos is inverse cosine. In 4D, add a_w b_w to the numerator and each w component squared to its magnitude sum. Convert radians to degrees with θ° = θ radians × 180/π, where π is pi.

The working above substitutes your component products and squared components explicitly. The numerical method uses an equivalent atan2 expression to retain small angles; see methodology.

Worked examples to load

Example values are rounded to four decimal places; the calculator keeps full internal precision.

2D acute

a = (3, 1); b = (2, 4).

Dot product: 10
Magnitudes: ‖a‖ = √10 ≈ 3.1623; ‖b‖ = √20 ≈ 4.4721
Cosine: 0.7071
Angle: 45° (0.7854 rad)

The vectors form an acute angle.

Perpendicular

a = (1, 0); b = (0, 2).

Dot product: 0
Magnitudes: ‖a‖ = 1; ‖b‖ = 2
Cosine: 0
Angle: 90° (1.5708 rad)

The vectors meet at a right angle.

Parallel

a = (1, 2); b = (2, 4).

Dot product: 10
Magnitudes: ‖a‖ = √5 ≈ 2.2361; ‖b‖ = √20 ≈ 4.4721
Cosine: 1
Angle: 0° (0 rad)

The vectors point in the same direction.

Opposite

a = (1, 2); b = (−2, −4).

Dot product: −10
Magnitudes: ‖a‖ = √5 ≈ 2.2361; ‖b‖ = √20 ≈ 4.4721
Cosine: −1
Angle: 180° (3.1416 rad)

The vectors point in opposite directions.

3D vectors

a = (1, 2, 3); b = (4, −5, 6).

Dot product: 12
Magnitudes: ‖a‖ = √14 ≈ 3.7417; ‖b‖ = √77 ≈ 8.7750
Cosine: 0.3655
Angle: 68.5624° (1.1966 rad)

The vectors form an acute angle in three dimensions.

Mixed components and points

a = (1, 0); b: initial (1, 2), terminal (2, 3), so b = (1, 1).

Dot product: 1
Magnitudes: ‖a‖ = 1; ‖b‖ = √2 ≈ 1.4142
Cosine: 0.7071
Angle: 45° (0.7854 rad)

The components and point pair describe an acute angle.

What the result means

  • Parallel, 0°: the vectors point in the same direction; cosine similarity is 1.
  • Acute, between 0° and 90°: the dot product and cosine are positive.
  • Perpendicular, 90°: the dot product and cosine are zero.
  • Obtuse, between 90° and 180°: the dot product and cosine are negative.
  • Opposite, 180°: the vectors are antiparallel; cosine similarity is −1.

The dot product is a scalar (a number). Magnitude is vector length. Cosine similarity is the dot product divided by both lengths, an alignment measure from −1 to 1. It is not itself an angle. Opposite vectors are also parallel in the broader sense of lying along parallel lines; here “Parallel” labels the same-direction case.

Unsigned angle versus direction or turn

This calculator returns the smallest unsigned geometric angle: 0°–180° (0–π radians). Swapping a and b gives the same answer. It does not specify a clockwise or counterclockwise turn.

A single vector’s direction angle measures it relative to the positive x-axis in 2D and can be found with atan2(y, x). A signed turn from a to b instead uses atan2(aₓbᵧ − aᵧbₓ, a · b), usually in the range −180° to 180°; positive means counterclockwise with x pointing right and y pointing up. Neither is the primary angle calculated here.

Calculation methodology and limitations

Last reviewed: — calculation logic, examples, and explanatory content.

We subtract initial coordinates from terminal coordinates for point inputs. Each vector is then divided by its largest absolute component to avoid overflow while calculating its direction. For scaled vectors u and v, we calculate d = Σ uᵢvᵢ and s = √(Σᵢ<ⱼ (uᵢvⱼ − uⱼvᵢ)²), then θ = atan2(s, d). Here i and j index components, Σ means sum, d is the scaled dot product, and s is the nonnegative area term. In 2D s is the absolute determinant; in 3D it is the cross-product magnitude. The same expression works in 4D.

This avoids taking arccos of a cosine rounded to 1 or −1 near parallel or opposite directions. Cosine similarity is clamped to [−1, 1] for tiny floating-point errors. The display precision never rounds intermediate calculations; scientific notation is used for very large or small numbers. Dot products and magnitudes beyond the ordinary number range are formatted using their scales.

  • Both vectors must be nonzero, real, and in the same dimension, expressed in a common Cartesian coordinate system with consistent coordinate units.
  • Identical initial and terminal points make a zero vector, whose angle is undefined.
  • JavaScript uses floating-point arithmetic, so extremely different component scales, cancellation, or point subtraction can lose precision. A coordinate difference outside the finite number range is rejected.
  • The relationship uses unrounded values. A nearly parallel, perpendicular, or opposite result can round to 0°, 90°, or 180° without being exactly that relationship.
  • The diagram is available for 2D only. It preserves equal axis scales, but a much shorter vector may be difficult to see.

References: OpenStax, Calculus Volume 3, §2.3: The Dot Product (identity and geometric angle), and §2.1: Vectors in the Plane (components, length, and direction).

Applications

Compare force and displacement directions in mechanics, check perpendicular edges in geometry, measure directional alignment in graphics, or compare feature vectors using cosine similarity. Position does not affect this angle: translate vectors to a common origin before comparing their directions.

Frequently asked questions

How do you compute the angle between two vectors?

For nonzero vectors, θ = arccos((a · b)/(‖a‖ ‖b‖)). Compute the dot product and both magnitudes, divide, then take inverse cosine. This calculator uses an equivalent atan2 formulation for numerical stability.

Why is the angle limited to 0°–180°?

The geometric angle is the smallest unsigned angle between the directions. Inverse cosine returns values from 0 to π radians, equivalent to 0°–180°; it does not encode a clockwise or counterclockwise turn.

What does a zero or negative dot product mean?

For two nonzero vectors, a zero dot product means perpendicular vectors and a 90° angle. A negative dot product means an obtuse angle or opposite directions at 180°. A positive dot product means an acute angle or the same direction at 0°.

Why does a zero vector have no angle?

A zero vector has no direction. Its magnitude is zero, so the dot-product angle formula would divide by zero. Identical initial and terminal points also produce a zero vector.

Must I normalize the vectors first?

No. Enter the original components or point pairs. Dividing the dot product by both magnitudes accounts for length automatically; the calculator also scales vectors internally for numerical stability.

Does vector length change the angle?

Multiplying either vector by a positive number changes its length but leaves the angle unchanged. Multiplying just one vector by a negative number reverses its direction and changes the angle to 180° minus the original angle. Scaling to zero makes the angle undefined.

How is this different from a single vector’s direction angle?

This angle compares two vectors. A 2D direction angle compares one vector with the positive x-axis, typically using atan2(y, x). A signed turn between vectors also includes clockwise or counterclockwise orientation.

Can I mix components and point pairs?

Yes. Each vector has its own Components or Two points selector. For a point pair, the calculator subtracts the initial point from the terminal point before calculating the angle.

Does this calculator support 3D and 4D?

Yes. Select 3D or 4D and enter every matching component or point coordinate. Results and working update live in all dimensions; the diagram is only for 2D.

Is cosine similarity the same as the angle?

No. Cosine similarity is cos θ, a number from −1 to 1. The angle θ is measured in degrees or radians. Cosine values of 1, 0, and −1 correspond to 0°, 90°, and 180°, respectively.

Related Vector Calculators

For more vector work, use the related tools above to find vector projections, dot products, cross products, and 2D or 3D distances.

Explore more tools