Skip to content

Lesson 3: 3D Rotation Matrices and Spatial Transformations

Learn 3D rotation mathematics through coordinate axis rotations, Euler angles, arbitrary axis methods (decomposition and Rodrigues formula), and homogeneous transformations applied to robotic welding, drone gimbals, and satellite attitude control.

🎯 Learning Objectives

By the end of this lesson, you will be able to:

  1. Construct rotation matrices for rotations about coordinate axes and arbitrary vectors
  2. Apply Euler angle sequences for systematic 3D orientation representation
  3. Compose 4×4 homogeneous transformation matrices for unified spatial motion
  4. Analyze transformation sequences understanding order-dependent composition

🔧 Real-World Engineering Challenge: 3D Spatial Orientation Control

Spatial orientation control is fundamental across robotics, aerospace, computer graphics, and automation. From industrial robots manipulating parts with precise tool angles, to spacecraft maintaining attitude in orbit, to animation systems rotating 3D models - all require mathematical frameworks for representing and composing 3D rotations and transformations.

Representative Systems

3D Spatial Control Applications:

  • Industrial Robots (6-DOF manipulators) - tool orientation for welding, machining, assembly
  • Aerospace Systems (satellites, aircraft) - attitude control and orientation tracking
  • Computer Graphics (animation, CAD) - 3D object rotation and camera positioning
  • Motion Capture Systems (biomechanics, VR) - tracking 3D body segment orientations
  • Coordinate Measuring Machines (CMMs) - probe orientation for complex surface inspection
  • Gimbals and Stabilizers (cameras, sensors) - maintaining orientation despite platform motion

The 3D Rotation Challenge

These systems require precise control of:

Engineering Question: How do we mathematically represent and compose complex 3D orientations in a systematic way that handles singularities and works across diverse applications?

Why 3D Spatial Mathematics Matters

Consequences of Poor Mathematical Foundation:

  • Orientation errors from incorrect rotation sequences or coordinate confusion
  • Gimbal lock causing loss of degrees of freedom at singular configurations
  • Numerical instability from poorly conditioned transformations
  • Programming complexity without systematic transformation framework
  • Limited scalability to more complex multi-body or hierarchical systems

Benefits of Systematic 3D Analysis:

  • Precise orientation control using robust mathematical representations
  • Predictable behavior through systematic matrix composition rules
  • Singularity awareness enabling detection and avoidance strategies
  • Unified framework applicable across robotics, aerospace, and graphics
  • Foundation for advanced topics (quaternions, screws, differential kinematics)

📚 Fundamental Theory: 3D Rotation Mathematics

Basic Rotation Matrices About Coordinate Axes

3D rotations are more complex than 2D because rotation order matters and multiple representations exist. Basic rotations about coordinate axes provide the building blocks for all spatial orientations. Following the established axis convention where counterclockwise rotation is positive, we can derive rotation matrices for each coordinate axis. Each rotation transforms a mobile frame (A, B, C) relative to a fixed frame (X, Y, Z).

Axes Convention

Rotation about X-axis by angle α:

Rotation about X Axis

Geometric Analysis:

After rotating axis B:

After rotating axis C:

Transformation Summary:

BeforeAfter
A(1,0,0)A(1,0,0)
B(0,1,0)B(0, cos α, sin α)
C(0,0,1)C(0, -sin α, cos α)

🔄 X-Axis Rotation Matrix

Physical Meaning: Rotation about X-axis corresponds to “roll” motion - like an aircraft banking left or right. Rotates vectors around the X-axis, leaving X-coordinates unchanged while rotating Y and Z components in the YZ-plane.

Rotation Matrix Properties

📐 Essential Rotation Matrix Properties

Orthogonality: (columns are orthonormal vectors) Determinant: (proper rotations, no reflections) Inverse: (transpose equals inverse) Composition: applies first, then , then

Physical Meaning: Rotation matrices preserve lengths and angles, representing pure rotations without scaling or reflection in 3D space.

4×4 Homogeneous Transformation Matrices

Extending the 2D homogeneous coordinate concept to 3D, we use 4×4 matrices to unify rotation and translation into a single mathematical operation. This powerful framework is the foundation for all modern robot kinematics and computer graphics.

🎯 Spatial Transformation Matrix

General 4×4 transformation:

Where:

  • = 3×3 rotation matrix
  • = 3×1 translation vector
  • = [0 0 0] zero vector
  • Last element = 1 (homogeneous coordinate)

Physical Meaning: 4×4 matrices unify rotation and translation into single mathematical operation for 3D spatial transformations.

Composite 3D Transformations for Robotics

Real robot control requires precise composition of multiple rotations and translations in 3D space. Understanding the systematic rules for matrix multiplication order is essential for accurate end-effector positioning and complex trajectory programming.

🔧 3D Transformation Composition Rules

Matrix multiplication is non-commutative - order matters!

For robot positioning with multiple transformations:

  1. Initial state: Fixed and mobile frames are coincident → Identity matrix
  2. Fixed frame operations: Rotate/translate about fixed axes (X,Y,Z) → Pre-multiply current matrix
  3. Mobile frame operations: Rotate/translate about mobile axes (A,B,C) → Post-multiply current matrix

General composition:

Where transformations are applied in sequence: H_1 first, H_n last.

Example 1: Simple 3D rotation and translation sequence
  1. Problem: 40° rotation about X-axis, then 7 units translation along mobile B-axis

    Setup: H = H(x,40°) · I · H(B,7)

  2. Matrix composition:

  3. Final result:

Euler Angle Representations

Euler angles provide an intuitive way to describe 3D orientations using three sequential rotations about coordinate axes. However, different sequences exist and singularities must be carefully managed. Additionally, the terminology (roll, pitch, yaw) depends heavily on which coordinate system convention is being used.

🎯 ZYX Euler Angles

Sequential rotations:

  1. Rotate γ about Z-axis (Roll in Math/Robotics convention)
  2. Rotate β about new Y-axis (Yaw in Math/Robotics convention)
  3. Rotate α about final X-axis (Pitch in Math/Robotics convention)

Combined rotation matrix:

Physical Meaning: Commonly used in robotics and computer graphics. The sequence applies Z rotation first, then Y rotation, then X rotation.

Note: Matrix multiplication order is right-to-left, so is applied first to the vector, then , then .

Rotation About an Arbitrary Axis Through the Origin

Rotation about an Arbitrary Axes

Rotation about an arbitrary axis is essential when the rotation cannot be decomposed into simple X, Y, Z rotations. Two primary methods exist: the decomposition approach and Rodrigues’ formula. Each has specific advantages depending on the application context.

Problem Setup: Given a fixed frame OXYZ and an arbitrary rotation axis V = (x,y,z) with components V_x, V_y, V_z, we need to construct the rotation matrix R(V,θ) for rotation angle θ.

Method 1: Decomposition Approach (General Arbitrary Axis Formula)

🔄 Arbitrary Axis Rotation Strategy

Five-step decomposition process:

  1. Rotation by angle α about X-axis
  2. Rotation by angle about Y-axis
  3. Rotation by angle θ about Z-axis
  4. Rotation by angle β about Y-axis
  5. Rotation by angle about X-axis

Matrix composition: R(V,θ) = R(x,-α) R(y,β) R(z,θ) R(y,-β) R(x,α)

The complete rotation matrix:

Geometric relationships: For unit vector |V| = 1:

⚡ Simplified Arbitrary Axis Formula

Final rotation matrix in compact form:

Where: C = cos θ, S = sin θ, T = (1 - cos θ)

Unit vector components:

Example: 90° rotation about V = (2, 2, 2)

Click to reveal decomposition method calculations
  1. Calculate unit vector components:

  2. Calculate trigonometric values:

  3. Compute matrix elements using compact formula:

  4. Final rotation matrix:

Method 2: Rodrigues’ Rotation Formula

Rodrigues’ formula provides a compact, elegant expression for arbitrary axis rotations using matrix exponentials and the skew-symmetric matrix form. This is the preferred method for computational implementations.

⚡ Rodrigues' Rotation Formula

Matrix exponential form:

Where:

  • I = 3×3 identity matrix
  • W = skew-symmetric matrix of unit vector
  • θ = rotation angle

Skew-symmetric matrix construction:

Key property: (outer product minus identity)

Note: Rodrigues formula only works for rotations about axes passing through the origin.

Example: Same 90° rotation about V = (2, 2, 2) using Rodrigues

Click to reveal Rodrigues method calculations
  1. Unit vector:

  2. Skew-symmetric matrix W:

  3. Compute W²:

  4. Apply Rodrigues formula:

    ✅ (same result!)

Comparison and Method Selection

CriterionDecompositionRodrigues
Computational costHigh (5 matrix mults)Low (2 matrix ops)
Code complexityMediumLow
Geometric intuitionExcellentPoor
Numerical stabilityGoodExcellent
Best use caseEducation, analysisImplementation
Connection toEuler anglesQuaternions

General recommendation: Use Rodrigues’ formula for all computational work (robot control, graphics engines, simulation). Use decomposition approach for teaching, learning, and analytical derivations.

🏭 Application 1: Robotic Welding of Pipe Joints (Manufacturing)

A 3-axis welding robot must perform orbital welding around a horizontal pipe with the torch perpendicular to the pipe surface at key positions around the weld.

🔧 Equivalent System Model

Pipe Welding Geometry

Given:

  • Pipe parameters: Radius R = 100 mm, horizontal pipe aligned with X-axis
  • Pipe centerline direction: (along X-axis)
  • Starting point: θ = 0° at top of pipe (pointing in +Z direction)
  • Torch requirements: Torch Z-axis must align with surface normal (pointing radially outward from pipe)
  • Waypoints: 4 cardinal points (θ = 0°, 90°, 180°, 270°)
  • Coordinate system: YZ-plane is perpendicular to pipe axis

Step 1: Surface Normal Calculation at Waypoints

Click to reveal surface normal calculations
  1. Understanding the coordinate system and notation:

    Coordinate system setup (RIGHT-HANDED):

    • The X-axis runs horizontally left-to-right (pipe direction)
    • The Y-axis points upward vertically (toward the ceiling)
    • The Z-axis points to the side (imagine lying along X-axis: legs at left, head at right, Z points to your left side)
    • Alternative Z-axis description: when viewing the XY plane on paper, Z comes out of the paper toward you
    • We look at the pipe’s circular cross-section in the YZ-plane

    Vector notation explained:

    • , , are unit vectors (length = 1) pointing along each axis
    • means “1 unit in X-direction, 0 in Y, 0 in Z”
    • means “0 in X, 1 unit in Y-direction (upward), 0 in Z”
    • means “0 in X, 0 in Y, 1 unit in Z-direction (out toward you)”
    • means “unit normal vector” (perpendicular to the pipe surface, pointing radially outward)

    Angular position θ convention:

    • We define θ = 0° at the TOP of the pipe (highest point, where normal points straight up in +Y direction)
    • θ increases as we rotate clockwise when viewing from the left (looking down the pipe in +X direction)
    • This is a choice of convention - we could pick any starting point, but starting at the top is intuitive
  2. Geometric reasoning - where does the normal point?

    Imagine standing at the left end of the pipe, looking at the circular cross-section in the YZ-plane:

    • At θ = 0° (top): Normal points straight up → +Y-direction →
    • At θ = 90° (toward you): Normal points out of paper → +Z-direction →
    • At θ = 180° (bottom): Normal points straight down → -Y-direction →
    • At θ = 270° (away from you): Normal points into paper → -Z-direction →
  3. Deriving the formula for surface normal:

    Looking at the circular cross-section in the YZ-plane, the normal vector rotates around the circle.

    At angle θ measured clockwise from the top:

    • The vertical component (Y) starts at 1, decreases: this follows cosine
    • The Z component (out of paper) starts at 0, increases: this follows sine

    General formula:

    This means: “Mix the up-direction () and out-of-paper direction () using cosine and sine to get the correct angle.”

  4. Calculating surface normal at θ = 0° (top of pipe):

    Substitute values: and

    Convert to coordinates:

    Interpretation:

    • X-component = 0 (doesn’t point along pipe)
    • Y-component = 1 (points straight up!)
    • Z-component = 0 (no out-of-paper component)
  5. Calculating surface normal at θ = 90° (side toward you):

    Substitute values: and

    Convert to coordinates:

    Interpretation:

    • X-component = 0 (doesn’t point along pipe)
    • Y-component = 0 (no vertical component)
    • Z-component = 1 (points out of paper toward you!)
  6. General formula in coordinate form:

    Written as a column vector:

  7. All 4 waypoint normal vectors:

    Pointθ (°)Calculationn_xn_yn_zPhysical Direction|n|
    00(0, cos 0°, sin 0°)010Top (+Y)1.000 ✅
    190(0, cos 90°, sin 90°)001Side (+Z, toward you)1.000 ✅
    2180(0, cos 180°, sin 180°)0-10Bottom (-Y)1.000 ✅
    3270(0, cos 270°, sin 270°)00-1Side (-Z, away)1.000 ✅

Step 2: Tool Orientation Matrix Construction

Click to reveal orientation matrix calculations
  1. What is a “tool frame” and why do we need it?

    The welding torch has its own coordinate system attached to it:

    • The torch must point perpendicular to the pipe surface (to make a good weld)
    • We need to describe which way the torch is pointing in 3D space
    • We do this by defining three perpendicular axes attached to the torch

    Tool frame axis definitions:

    • Z-axis (torch tip direction): Points where the torch is aimed - must align with surface normal to be perpendicular to pipe
    • X-axis (torch advance direction): Points along the welding direction - we choose this to be along the pipe axis =
    • Y-axis (torch side direction): Points to the side of the torch - calculated automatically to complete a right-handed coordinate system

    Why these choices?

    • Z-axis MUST be perpendicular to the pipe (required for welding)
    • X-axis along the pipe makes sense because the torch moves along the pipe
    • Y-axis is whatever’s left to make the three axes perpendicular to each other
  2. Tool orientation at θ = 0° (top of pipe):

    What we know:

    • At the top, the surface normal points straight up:
    • This means the torch must point upward too

    Building the tool frame step-by-step:

    Step 2a: Z-axis (where torch points):

    • Torch must be perpendicular to pipe surface
    • At top of pipe, this means pointing upward (in +Y direction):

    Step 2b: X-axis (welding direction):

    • We choose this to be along the pipe:

    Step 2c: Y-axis (complete the frame):

    • Must be perpendicular to both X and Z axes
    • We use the cross product:

    Cross product calculation:

    Using cross product formula:

    Step 2d: Build the rotation matrix:

    • A rotation matrix has the tool frame axes as its columns
    • Format: (three column vectors side-by-side)

    Physical meaning: At the top of the pipe, the torch points upward (+Y), moves along the pipe (+X), with Y-axis pointing away from you (-Z). ✅

  3. Tool orientation at θ = 90° (side toward you):

    What we know:

    • At the side, the surface normal points out toward you:
    • This means the torch must point toward you

    Building the tool frame:

    Step 3a: Z-axis (where torch points):

    • Must point toward you (in +Z direction):

    Step 3b: X-axis (welding direction):

    • Still along the pipe:

    Step 3c: Y-axis (cross product):

    Step 3d: Build the rotation matrix:

    Physical meaning: At θ = 90°, the tool frame aligns with the world frame! The torch points toward you (+Z), moves along pipe (+X), with Y-axis pointing up (+Y). ✅

  4. Complete the other waypoints (θ = 180° and 270°):

    Following the same process for the bottom and other side:

    At θ = 180° (bottom):

    • Surface normal: (points down)
    • Z-axis: , X-axis:
    • Y-axis:

    Rotation matrix:

    At θ = 270° (away from you):

    • Surface normal: (points away)
    • Z-axis: , X-axis:
    • Y-axis:

    Rotation matrix:

  5. Summary table of all 4 waypoints:

    θ (°)PositionTorch PointsX-axisY-axisZ-axisR_tool (3×3 matrix)
    0TopUp (+Y)(1,0,0)(0,0,-1)(0,1,0)
    90SideToward you (+Z)(1,0,0)(0,1,0)(0,0,1)
    180BottomDown (-Y)(1,0,0)(0,0,1)(0,-1,0)
    270SideAway (-Z)(1,0,0)(0,-1,0)(0,0,-1)
  6. Important pattern to recognize:

    Look at the first column of all the matrices - it’s always !

    • This is the X-axis, which always points along the pipe
    • This column never changes because the torch always moves along the pipe axis

    The key insight:

    • All these matrices represent pure rotations about the X-axis (the pipe)
    • θ = 0°: Rotation by some angle about X-axis
    • θ = 90°: Identity (world frame aligned)
    • θ = 180°: Another rotation about X-axis
    • θ = 270°: Another rotation about X-axis

    Physical interpretation:

    • Imagine holding the pipe with your right hand, thumb pointing along +X
    • As you rotate around the pipe clockwise (when viewing from left), the torch rotates with you
    • The torch always stays perpendicular to the pipe surface
    • You’re just doing a simple roll motion about the pipe axis!

Step 3: Euler Angle Extraction (ZYX Convention)

Click to reveal Euler angle extraction
  1. What are Euler angles and why do we need them?

    The problem:

    • We have rotation matrices that describe the torch orientation
    • But robot controllers don’t understand matrices directly
    • They need three simple rotation angles: roll, pitch, and yaw

    What are Euler angles?

    • Roll (α): Rotation about X-axis (like a plane banking left/right)
    • Pitch (β): Rotation about Y-axis (like a plane nose up/down)
    • Yaw (γ): Rotation about Z-axis (like a plane turning left/right)

    ZYX convention means: apply rotations in order Z, then Y, then X (but we extract them in reverse!)

  2. The extraction formulas (you don’t need to memorize these!):

    Given rotation matrix :

    These formulas extract the angles by looking at specific matrix elements:

    • Pitch (β): (looks at position row 3, column 1)
    • Roll (α): (looks at positions row 3, columns 2 & 3)
    • Yaw (γ): (looks at positions rows 2 & 1, column 1)

    Don’t worry about deriving these - they come from the ZYX rotation sequence definition. Just know how to use them!

  3. Extracting Euler angles at θ = 0° (top of pipe):

    Our rotation matrix:

    Labeling the elements:

    Calculating pitch:

    Calculating roll:

    Calculating yaw:

    Result: (roll, pitch, yaw) = (-90°, 0°, 0°)

    Physical meaning: A -90° roll about X-axis - torch points upward.

  4. Extracting Euler angles at θ = 90° (side toward you):

    Our rotation matrix:

    Labeling the elements:

    Calculating pitch:

    Calculating roll:

    Calculating yaw:

    Result: (roll, pitch, yaw) = (0°, 0°, 0°)

    Physical meaning: This is the “home” position - torch points toward you at the side of the pipe.

  5. What about gimbal lock (singularities)?

    The danger zone: If pitch β = ±90°, the formulas break down (gimbal lock!)

    Checking for gimbal lock:

    • Singularity happens when
    • For all our waypoints:
    • Therefore: ✅ (safe!)

    Why are we safe?

    • Our torch never pitches up or down (pitch always = 0°)
    • We only roll around the pipe
    • The horizontal pipe geometry prevents gimbal lock!
  6. Summary: Euler angles for all 4 waypoints:

    Calculating for the remaining two waypoints (θ = 180° and 270°) using the same formulas:

    Pointθ (°)PositionRoll α (°)Pitch β (°)Yaw γ (°)Robot CommandSingular?
    00Top-9000”Roll -90°“No ✅
    190Side (+Z)000”Home position”No ✅
    2180Bottom+9000”Roll +90°“No ✅
    3270Side (-Z)±18000”Roll ±180°“No ✅

    The beautiful insight:

    • Only roll (α) changes - pitch and yaw stay zero!
    • This confirms our physical intuition: we’re just rotating around the pipe (X-axis)
    • θ = 90° is our “home/reference” position (identity matrix)
    • Moving clockwise from θ = 90°: roll angle = -(θ - 90°)
    • No complex 3D orientation calculations needed during welding!

Step 4: Verification - Torch Perpendicularity Check

Click to reveal verification calculations
  1. Verification method:

    For each waypoint, verify that the torch Z-axis (third column of rotation matrix) equals the surface normal.

  2. Waypoint θ = 0° (top of pipe):

    Expected: Surface normal (pointing up)

    From rotation matrix: , third column

    Torch perpendicularity: ✅ (perfect alignment)

  3. Waypoint θ = 90° (side toward you):

    Expected: Surface normal (pointing toward you)

    From rotation matrix: , third column

    Torch perpendicularity: ✅ (perfect alignment)

  4. All waypoints verification summary:

    θ (°)Surface NormalTorch Z-axisDot ProductPerpendicular?
    0(0, 1, 0)(0, 1, 0)1.0✅ Yes
    90(0, 0, 1)(0, 0, 1)1.0✅ Yes
    180(0, -1, 0)(0, -1, 0)1.0✅ Yes
    270(0, 0, -1)(0, 0, -1)1.0✅ Yes

🏭 Application 2: Drone Camera Gimbal Stabilization (Aerial Photography)

A 2-axis camera gimbal must compensate for drone tilting to keep the camera pointing straight down at the ground.

🔧 Equivalent System Model

Gimbal Coordinate Frames

Given:

  • Drone attitude: Roll φ = 10°, Pitch θ = 20°, Yaw ψ = 0° (ignore yaw for simplicity)
  • Camera desired orientation: Pointing straight down (-Y direction)
  • Coordinate system: X = forward, Y = up, Z = right
  • Gimbal convention: Roll about X-axis, then Pitch about Y-axis

Step 1: Drone Orientation Matrix from Euler Angles

Click to reveal drone orientation calculations
  1. Understanding the problem:

    The situation:

    • The drone body is tilted from level flight
    • Roll φ = 10° (drone is banking to the right)
    • Pitch θ = 20° (drone nose is pitched up)
    • We need to describe this tilt using a rotation matrix

    What we’re calculating:

    • A 3×3 matrix that describes how the drone is oriented relative to the ground
    • This matrix will help us figure out how to compensate with the gimbal
  2. Rotation sequence explanation:

    We apply rotations in this order:

    1. First: Roll about X-axis by φ = 10°
    2. Second: Pitch about Y-axis by θ = 20°
    3. (Yaw is 0° so we skip it)

    Combined formula:

  3. Step-by-step: Roll rotation matrix (X-axis, φ = 10°):

    Formula for X-axis rotation:

    Substitute φ = 10°:

    Physical meaning: Rotating 10° about X-axis (banking right) - like tilting your head to the right.

  4. Step-by-step: Pitch rotation matrix (Y-axis, θ = 20°):

    Formula for Y-axis rotation:

    Substitute θ = 20°:

    Physical meaning: Rotating 20° about Y-axis (pitching up) - like nodding your head upward.

  5. Combining the rotations (matrix multiplication):

    Matrix multiplication (showing key elements):

    Element (1,1):

    Element (1,2):

    Element (1,3):

    Element (2,1):

    Element (2,2):

    Element (2,3):

    Element (3,1):

    Element (3,2):

    Element (3,3):

    Result:

  6. What does this matrix tell us?

    Each column of the matrix tells us where the drone’s axes point:

    • Column 1 (X-axis): Where the drone’s “forward” direction points
    • Column 2 (Y-axis): Where the drone’s “up” direction points
    • Column 3 (Z-axis): Where the drone’s “right” direction points

    The drone’s “up” direction (column 2) is (0.0594, 0.9848, 0.1631) - mostly still pointing up (Y=0.9848), but tilted slightly forward and to the side.

Step 2: Desired Camera Orientation Matrix

Click to reveal desired orientation calculations
  1. What do we want the camera to do?

    The goal:

    • Camera should point straight down toward the ground
    • This means the camera’s “down” direction should align with the world’s “down” direction (-Y)
    • The camera should be level (not tilted/rolled)

    In our coordinate system:

    • World “down” = -Y direction = (0, -1, 0)
    • Camera optical axis points along its own Z-axis
    • So we want camera Z-axis = (0, -1, 0)
  2. What is the desired orientation matrix?

    When the camera points straight down with no rotation:

    • Camera X-axis (forward) points along world X-axis: (1, 0, 0)
    • Camera Y-axis (up on camera) points along world Z-axis: (0, 0, 1)
    • Camera Z-axis (optical axis) points down: (0, -1, 0)

    Building the matrix from these column vectors:

  3. Verification - does the camera point down?

    Apply the rotation to the camera’s Z-axis unit vector (0, 0, 1):

    Result: (0, -1, 0) means the camera points straight down in the -Y direction! ✅

  4. Physical meaning:

    This matrix represents a 90° rotation about the X-axis:

    • Imagine starting with the camera pointing forward
    • Rotate it 90° down (nose down) about the X-axis
    • Now it points straight at the ground

Step 3: Gimbal Compensation Calculation

Click to reveal gimbal compensation calculations
  1. Understanding the problem:

    The relationship:

    • The camera is mounted on the gimbal
    • The gimbal is mounted on the drone
    • Camera orientation in world = (Drone orientation) × (Gimbal orientation)

    Mathematically:

    What we know:

    • = how the drone is tilted (calculated in Step 1)
    • = we want camera pointing straight down (from Step 2)
    • = this is what we need to find!
  2. Solving for the gimbal orientation:

    From:

    We can solve for by multiplying both sides by (the inverse):

    Key trick: For rotation matrices, the inverse equals the transpose!

  3. Calculate the drone’s inverse (transpose):

    From Step 1, we had:

    Transpose (swap rows and columns):

  4. Calculate gimbal compensation matrix:

    Matrix multiplication (showing all 9 elements):

    Row 1:

    • (1,1):
    • (1,2):
    • (1,3):

    Row 2:

    • (2,1):
    • (2,2):
    • (2,3):

    Row 3:

    • (3,1):
    • (3,2):
    • (3,3):

    Result:

  5. What does this mean?

    This matrix tells the gimbal: “To cancel out the drone’s tilt and point the camera straight down, you need to rotate in the opposite direction of the drone’s tilt.”

Step 4: Extract Gimbal Euler Angles (Roll and Pitch)

Click to reveal Euler angle extraction
  1. Why extract Euler angles?

    • The gimbal motors need simple angle commands: “rotate roll by X°, pitch by Y°”
    • We have a 3×3 matrix, but need to extract the roll and pitch angles from it
    • This is the reverse of what we did in Step 1
  2. Euler angle extraction formulas:

    Given rotation matrix :

    • Pitch (θ):
    • Roll (φ):

    Our gimbal matrix:

  3. Calculate pitch:

    Physical meaning: Gimbal needs to pitch down by 20° to compensate for drone pitching up by 20°!

  4. Why Euler angle extraction is tricky here:

    Extracting Euler angles from the gimbal compensation matrix is more complex than it might seem for a 2-axis gimbal. The matrix we calculated represents the combined compensation needed, but extracting meaningful roll and pitch angles depends on the specific rotation sequence the gimbal hardware uses.

    The key insight:

    • The gimbal needs to rotate opposite to the drone’s motion
    • Drone rolled 10° right → gimbal should roll ~10° left
    • Drone pitched 20° up → gimbal should pitch ~20° down
  5. Better approach: Direct verification

    Instead of extracting Euler angles, let’s verify directly that the camera points down after compensation (Step 5).

Step 5: Verification - Does the Camera Point Straight Down?

Click to reveal verification calculations
  1. The test: Does the final camera point straight down?

    We need to verify:

    What we’ll check:

    • Apply the gimbal compensation to the tilted drone
    • See where the camera’s Z-axis (optical axis) ends up pointing
    • It should point straight down: (0, -1, 0)
  2. Calculate final camera orientation:

    We only need to check where the camera Z-axis points (third column of result):

    Camera Z-axis = = (third column of )

    Element (1,3):

    Element (2,3):

    Element (3,3):

    Result: Camera Z-axis points to = straight down! ✅

  3. Success!

    The gimbal compensation works perfectly:

    • Drone is tilted (roll = 10°, pitch = 20°)
    • Gimbal compensates with opposite rotations
    • Camera ends up pointing straight down at the ground

🏭 Application 3: Satellite Attitude Control for Solar Tracking (Space Systems)

A satellite needs to reorient its solar panels to point toward the sun using reaction wheel actuation.

🔧 Equivalent System Model

Satellite Geometry

Given:

  • Spacecraft body frame: X = velocity direction, Y = radial (toward Earth), Z = orbit normal
  • Solar panel normal (current): Along +Z body axis = [0, 0, 1]
  • Sun direction (in body frame): [0.6, 0, 0.8] (normalized)
  • Solar panel area: 2.5 m², efficiency 30%
  • Task: Find rotation matrix R that aligns panel normal with sun direction

What makes this interesting:

  • We cannot decompose this into simple X, Y, Z rotations easily
  • Instead, we use Rodrigues formula for arbitrary axis rotation
  • This is how real spacecraft attitude control systems work

Step 1: Identify Current and Desired Panel Orientations

Click to reveal vector setup
  1. Current solar panel normal (before rotation):

    The solar panel is mounted on the spacecraft with its normal vector pointing along the +Z body axis.

    Physical interpretation: Panel faces “up” relative to orbit plane.

  2. Sun direction in body frame:

    At this moment in the orbit, sensors measure the sun direction in the spacecraft body frame:

    Verify this is a unit vector:

    Physical interpretation: Sun is in the XZ-plane (no Y-component), pointing mostly forward (+X) and somewhat “up” (+Z).

  3. Desired panel normal (after rotation):

    To maximize solar power, we want the panel normal to point directly at the sun:

  4. Visualization of the rotation problem:

    VectorDirectionCoordinates
    Current normalAlong +Z axis[0, 0, 1]
    Sun directionIn XZ-plane[0.6, 0, 0.8]
    Need to rotateFrom current to sun?

    Key observation: Both vectors lie in the XZ-plane (Y-component is zero for both), so the rotation axis must be perpendicular to the XZ-plane (i.e., along Y-axis or close to it).

Step 2: Calculate Rotation Axis and Angle

Click to reveal rotation axis and angle calculations
  1. Find the rotation axis using cross product:

    The rotation axis must be perpendicular to both the current panel normal and the desired (sun) direction. We use the cross product:

    Cross product formula reminder:

    Apply the formula:

    • X-component:
    • Y-component:
    • Z-component:

    Physical interpretation: Rotation axis points along +Y (toward Earth). This makes sense since both the current normal and sun direction are in the XZ-plane.

  2. Normalize to get unit rotation axis:

    Result: Unit rotation axis is exactly the +Y body axis.

  3. Calculate rotation angle using dot product:

  4. Verify using cross product magnitude:

    For unit vectors:

    Check trigonometric identity:

  5. Summary of rotation parameters:

    ParameterValuePhysical Meaning
    Rotation axis[0, 1, 0]Along +Y (toward Earth)
    Rotation angle36.87°Tilt panel forward toward sun
    Rotation directionRight-hand ruleThumb along +Y, fingers curl from +Z toward +X

Step 3: Build Rotation Matrix Using Rodrigues Formula

Click to reveal Rodrigues rotation matrix construction
  1. Rodrigues rotation formula:

    For a rotation by angle φ about unit axis :

    Where:

    • = 3×3 identity matrix
    • = skew-symmetric matrix of
    • = rotation angle

    Why this works: Rodrigues formula gives the same result as rotating a vector around an arbitrary axis, derived from exponential map of rotation.

  2. Construct skew-symmetric matrix W:

    For rotation axis :

    Physical meaning: The skew-symmetric matrix represents the cross product operation with .

  3. Calculate :

    Element-by-element multiplication:

    • Row 1, Col 1:
    • Row 1, Col 2:
    • Row 1, Col 3:
    • Row 2, Col 1:
    • Row 2, Col 2:
    • Row 2, Col 3:
    • Row 3, Col 1:
    • Row 3, Col 2:
    • Row 3, Col 3:

  4. Apply Rodrigues formula with φ = 36.87°:

    Add element-by-element:

  5. Physical interpretation of the rotation matrix:

    This is a rotation about the Y-axis by 36.87°. Notice:

    • Middle row/column unchanged: [0, 1, 0] (Y-axis is rotation axis)
    • X and Z components mix according to rotation angle
    • This is exactly from standard rotation matrix formulas

    Comparison to standard Y-axis rotation:

    Key insight: For this problem, Rodrigues formula gives us the same result as a simple Y-axis rotation. But Rodrigues formula works for ANY arbitrary axis, not just X, Y, or Z!

Step 4: Verify the Rotation Works

Click to reveal verification
  1. Apply rotation to current panel normal:

    Matrix-vector multiplication:

    • X-component:
    • Y-component:
    • Z-component:

  2. Compare to desired (sun direction):

    Desired:

    Actual:

    Perfect match!

  3. Calculate solar power output:

    Solar panels generate maximum power when perpendicular to sunlight. Power follows cosine law:

    Dot product (alignment factor):

    Maximum possible power:

    Actual power (perfect alignment):

    This is maximum possible power from these solar panels!

  4. Summary:

    ParameterValueStatus
    Rotation axis[0, 1, 0] (Y-axis)
    Rotation angle36.87°
    Panel alignmentPerfect (error = 0)
    Solar power1025 W✅ Maximum
    MethodRodrigues formula

📋 Summary and Next Steps

In this lesson, you learned 3D rotation and transformation mathematics through theory and applications.

Key Skills Developed:

  1. Construct rotation matrices for X, Y, Z coordinate axes using trigonometric relationships
  2. Apply Euler angle sequences (ZYX, ZYZ) while managing singularities and gimbal lock
  3. Calculate arbitrary axis rotations using decomposition method or Rodrigues formula
  4. Compose 4×4 homogeneous transformation matrices for unified rotation and translation

Two Methods for Arbitrary Axis Rotations:

  • Decomposition approach: Intuitive 5-step geometric method (best for education and analysis)
  • Rodrigues formula: (best for implementation)

Applications Covered:

  • Robotic welding - Surface normals, tool orientation matrices, SLERP interpolation
  • Drone gimbal stabilization - Matrix inversion, real-time compensation at 200Hz
  • Satellite attitude control - Rodrigues formula for sun tracking with dual constraints

Critical Properties:

  • Rotation matrices are orthogonal: R⁻¹ = Rᵀ
  • Euler angles have gimbal lock at pitch = ±90°
  • Matrix multiplication order matters: R₃R₂R₁ applies R₁ first

Coming Next: Lesson 4 develops systematic kinematic modeling using DH parameters for Stewart Platform analysis.

Comments

© 2021-2025 SiliconWit. All rights reserved.