How Do You Find the Signed Angle Between Two Vectors?
At a glance
- 1. Check the setting
A signed angle is well-defined in an oriented plane; in 3D, choose a plane normal or rotation axis.
- 2. Compute dot and determinant
The dot product gives the cosine-related component; the 2D determinant gives the direction of rotation.
- 3. Use atan2
Apply atan2 to the determinant and dot product, in that order, to get the directed angle.
- 4. Check edge cases
A zero vector has no angle, and exactly opposite vectors have an ambiguous sign at 180 degrees.
The ordinary angle between two vectors is unsigned: it measures how far apart their directions are, from 0° to 180°. A signed angle also records which way you rotate from the first vector to the second. In a 2D coordinate system, counterclockwise rotation is conventionally positive and clockwise rotation negative.
For nonzero vectors and , calculate the signed angle from to with
The result is in radians unless you convert it to degrees. The order matters: this formula measures the rotation from to .
Why the formula works
The dot product and the 2D determinant encode the cosine and sine components of the angle:
u\cdot v=\|u\|\|v\|\cos\theta,$$u_xv_y-u_yv_x=|u||v|\sin\theta.$$
The function returns the angle whose sine-related input is and cosine-related input is , while keeping track of the correct quadrant. Here, the determinant is the first input and the dot product is the second.
This is usually preferable to finding and guessing the sign afterward. The arccosine formula gives only an unsigned angle and can lose precision when its input is close to 1 or −1.
Worked example
Find the signed angle from to .
First compute the determinant:
u_xv_y-u_yv_x=(1)(1)-(2)(-2)=5.$$ Then compute the dot product:u\cdot v=(1)(-2)+(2)(1)=0.$$
Therefore,
The positive sign means the rotation from to is counterclockwise. Reversing the vectors changes the determinant’s sign, so the angle from to is .
As a quick clockwise example, let and . The determinant is and the dot product is , so .
Converting units and using software
Most programming languages provide an atan2 function with inputs ordered as atan2(y, x). Pass the determinant first and the dot product second. For example, in Python:
import math
u = (1, 2)
v = (-2, 1)
det = u[0] * v[1] - u[1] * v[0]
dot = u[0] * v[0] + u[1] * v[1]
angle_radians = math.atan2(det, dot)
angle_degrees = math.degrees(angle_radians)
This gives angle_degrees equal to 90. If you need an angle in the range 0° to 360° instead of a signed angle, add 360° to a negative result. That changes the representation, not the rotation.
What changes in 3D?
Two vectors in 3D still have a well-defined unsigned angle, but there is no unique positive rotation direction without additional information. The vectors lie in a plane through the origin, but that plane can be assigned either orientation.
If you choose a unit normal to the plane, the signed angle from to relative to that normal is
Changing to reverses the sign. The displayed cross-product formula is specific to 3D. For vectors in a higher-dimensional space, choose an oriented 2D plane containing them and use their coordinates in an oriented orthonormal basis of that plane in the 2D determinant-and-dot-product formula.
Common mistakes
- Swapping the inputs to
atan2: Use the determinant as the first input and the dot product as the second. Reversing them generally gives a different angle. - Using the determinant in the wrong order: measures from to . Reversing the vectors flips the sign.
- Treating the sign as absolute in 3D: A signed 3D angle requires a chosen normal or axis; the vectors alone do not determine one.
- Using a zero vector: The direction of the zero vector is undefined, so no angle involving it is defined.
- Expecting a unique sign for opposite vectors: If vectors point in exactly opposite directions, the determinant is zero and the unsigned angle is 180°. Either direction around the plane reaches the same endpoint, so the signed choice depends on convention or numerical details. Near this case, small rounding errors can affect the reported sign.
References
- Gilbert Strang, Introduction to Linear Algebra
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.