Rodrigues Rotation Formula
Implement Rodrigues' rotation formula to rotate a 3D point around an arbitrary axis.
Given axis k (unit vector) and angle θ, the rotated point is:
vrot=vcosθ+(k×v)sinθ+k(k⋅v)(1−cosθ)
This decomposes as:
- Component parallel to axis (unchanged by rotation)
- Component perpendicular to axis (rotated in the plane)
Used in camera pose estimation, 3D reconstruction, and robotics.
Example:
point = [1, 0, 0] axis = [0, 0, 1] # Z-axis angle = 1.5708 # ~90 degrees
[0.0, 1.0, 0.0]
Rotating [1,0,0] around Z-axis by 90°:
- k × v = [0,0,1] × [1,0,0] = [0,1,0]
- k · v = 0 (perpendicular)
v_rot = [1,0,0]·cos(90°) + [0,1,0]·sin(90°) + 0 = [0,0,0] + [0,1,0] = [0,1,0]
Constraints:
- point: 3D point [x, y, z]
- axis: Unit vector defining rotation axis
- angle: Rotation angle in radians
- Return: Rotated point, rounded to 4 decimals
Rodrigues’ rotation formula gives a closed-form expression for rotating a 3D vector around an arbitrary axis using basic vector operations: dot product, cross product, and scalar multiplication. It expresses the rotated vector \mathbf{v}rot as a sum of three geometrically meaningful components: the original vector scaled by cos\theta, a perpendicular component obtained via the cross product scaled by sin\theta, and a projection of \mathbf{v} onto the axis scaled by 1−cos\theta. This avoids building a full 3×3 rotation matrix explicitly, while being mathematically equivalent to a rotation in SO(3).
Geometrically, any vector \mathbf{v} can be decomposed into a part parallel to the rotation axis \mathbf{k} and a part perpendicular to it. The parallel component is unchanged by rotation, while the perpendicular component rotates in the plane orthogonal to \mathbf{k} by angle \theta. In computer vision and robotics, this axis–angle parameterization is widely used to represent camera orientation, perform pose updates, and convert between rotation matrices and more compact representations.
1. Background Knowledge (Key Concepts)
-
Axis–angle representation A 3D rotation can be represented by:
-
A unit axis \mathbf{k}∈R3 (direction of rotation)
-
A rotation angle \theta (right-hand rule about \mathbf{k}) Rodrigues’ formula maps this pair (\mathbf{k},\theta) and a vector \mathbf{v} to the rotated vector \mathbf{v}rot.
-
Vector operations involved
-
Dot product \mathbf{k}⋅\mathbf{v}: projection of \mathbf{v} on the axis.
-
Cross product \mathbf{k}×\mathbf{v}: vector orthogonal to both \mathbf{k} and \mathbf{v}, giving the direction of infinitesimal rotation.
-
Decomposition: \mathbf{v}=\mathbf{v}∥+\mathbf{v}⊥ where \mathbf{v}∥=(\mathbf{k}⋅\mathbf{v})\mathbf{k}, \mathbf{v}⊥=\mathbf{v}−\mathbf{v}∥. Only \mathbf{v}⊥ actually “spins” in the rotation.
2. Algorithm / General Approach
You are given:
- A unit axis \mathbf{k}=(kx,ky,kz)
- An angle \theta
- A 3D point/vector \mathbf{v}=(x,y,z)
You need to compute:
vrot=vcosθ+(k×v)sinθ+k(k⋅v)(1−cosθ)The algorithm pattern is:
- Precompute cos\theta and sin\theta.
- Compute the dot and cross of \mathbf{k} and \mathbf{v}.
- Form each term of the formula with scalar–vector multiplies.
- Sum the three terms to get the rotated vector.
This is a direct formula evaluation (constant time, no loops).
3. Step-by-Step Strategy to Implement
Assume inputs:
- k = (kx, ky, kz) (axis, should be unit)
- theta (angle, in radians)
- v = (vx, vy, vz) (point or direction)
- (Optionally) normalize the axis If the problem does not guarantee a unit axis, normalize:
norm = sqrt(kx*kx + ky*ky + kz*kz)
kx, ky, kz = kx/norm, ky/norm, kz/norm
- Precompute trigonometric values
c = cos(theta) # cosθ
s = sin(theta) # sinθ
one_minus_c = 1 - c
- Compute dot product \mathbf{k}⋅\mathbf{v}
kv = kx*vx + ky*vy + kz*vz # scalar
- Compute cross product \mathbf{k}×\mathbf{v}
cx = ky*vz - kz*vy
cy = kz*vx - kx*vz
cz = kx*vy - ky*vx
- Assemble the three terms of Rodrigues’ formula
- First term: \mathbf{v}cos\theta
term1x = vx * c
term1y = vy * c
term1z = vz * c
- Second term: (\mathbf{k}×\mathbf{v})sin\theta
term2x = cx * s
term2y = cy * s
term2z = cz * s
- Third term: \mathbf{k}(\mathbf{k}⋅\mathbf{v})(1−cos\theta)
scale = kv * one_minus_c
term3x = kx * scale
term3y = ky * scale
term3z = kz * scale
- Sum terms to get the rotated vector
vrot_x = term1x + term2x + term3x
vrot_y = term1y + term2y + term3y
vrot_z = term1z + term2z + term3z
- Return (vrot_x,vrot_y,vrot_z).
This is the full computation pattern; details like language syntax differ but the operations are identical.
4. Common Pitfalls
-
Axis not normalized Rodrigues’ formula assumes ∥\mathbf{k}∥=1. If it is not, the rotation will scale or distort the vector. Either:
-
Normalize k yourself, or
-
Trust the problem’s guarantee and avoid double-normalizing.
-
Degrees vs radians Most math libraries expect radians. If you are given degrees, convert:
theta_rad = theta_deg * pi / 180.0
-
Incorrect cross product order The formula uses \mathbf{k}×\mathbf{v}, not \mathbf{v}×\mathbf{k}. Reversing order flips the sign of the rotation (clockwise vs counterclockwise).
-
Floating point precision For very small \theta, sin(theta) and 1 - cos(theta) can become numerically delicate. Using standard sin and cos is usually fine, but be aware of rounding errors if you later rely on length being exactly preserved.
-
Confusing point vs vector Rodrigues’ formula applies to vectors from the origin. If you are rotating a point around an axis not passing through the origin, you must:
-
Translate the point so that the axis passes through the origin.
-
Apply Rodrigues’ formula.
-
Translate back.
5. Time & Space Complexity
-
Time complexity The computation is a constant number of scalar operations (adds, multiplies, trig calls, dot/cross products), so:
-
Time: O(1) per vector.
-
Space complexity
-
You store a constant number of scalars and vectors (no arrays growing with input size):
-
Space: O(1).
This makes Rodrigues’ formula very efficient for repeated 3D rotations in vision, graphics, and robotics.