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
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.
Degrees
—
Radians
—
Dot product a · b
—
Magnitude ‖a‖
—
Magnitude ‖b‖
—
Cosine similarity
—
Vector relationship
—
Step-by-step working
Working appears when all inputs are valid.
2D vector 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
Choose 2D, 3D, or 4D and your display precision.
For each vector, independently choose Components or Two points. For point pairs, enter the initial and terminal coordinates; the vector is terminal minus initial.
Enter every coordinate. Results, working, and the 2D diagram update automatically, or press Calculate.
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:
In text: a · b = ‖a‖ ‖b‖ cos θ
Divide both sides by the positive product of the magnitudes, then take the inverse cosine:
In text: cos θ = (a · b)/(‖a‖ ‖b‖), so θ = arccos((a · b)/(‖a‖ ‖b‖)).
Expanded 2D formula
In text: θ = arccos((ax bx + ay by) / (√(ax² + ay²) √(bx² + by²))).
Expanded 3D formula
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.
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.
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.