BRAGA

02 Writing02-02 Notes02-02-208

Rotation about e₂-axis

Published 16 Apr 20267 min read
Contents
  1. 01Deep Breakdown
  2. 02Flowchart
  3. 03Real-world use
  4. 04The formula, piece by piece
  5. 05The formula in words
  6. 06Critical Concepts
  7. 07Step-by-step calculation (tiny example)
  8. 08Code examples
R2(θ)=[cos⁡θ0sin⁡θ010−sin⁡θ0cos⁡θ]R_2(\theta) = \begin{bmatrix} \cos\theta & 0 & \sin\theta \\ 0 & 1 & 0 \\ -\sin\theta & 0 & \cos\theta \end{bmatrix}
(1)

Deep Breakdown

What it tells me (Situation Awareness): R2(θ)R_2(\theta) is the 3D rotation matrix that rotates vectors by angle θ\theta around the yy-axis (e2e_2-axis). The yy-coordinate is unchanged; the xx-zz plane rotates. This is the "pitch" rotation in aerospace/robotics. Note the sign pattern: the sin⁡θ\sin\theta entries have opposite signs compared to R1R_1 and R3R_3 — the off-diagonal signs are flipped. This is because rotating the xz-plane by θ\theta around yy follows the right-hand rule differently than the yz or xy plane. In DA/DS: pitch rotation is used in 3D data augmentation, robotics, sensor orientation modeling, and composing Euler angle rotations.

Flowchart

Input vector: (x,y, z)^T, anglethetaApply R2(theta)x-component:x*cos(theta) +z*sin(theta)y-component:unchanged (ystays y)z-component:-x*sin(theta) +z*cos(theta)Output:(x*cos+z*sin, y,-x*sin+z*cos)^TRotation in thexz-plane byangle thetaNOTE: sin signsflipped vs R1and R3

Real-world use

Where it is used

Modeling pitch of drones/cameras in aerial imaging datasets (rotating scene around the horizontal yy-axis), composing full 3D orientation with Euler angles (R=R3R2R1R = R_3 R_2 R_1), 3D data augmentation for models that should be robust to up-tilt variations, and geodetic coordinate transforms (pitch component of IMU data).

Problem it solves

Applying a rigid pitch rotation to 3D vectors or point clouds. The yy-axis acts as the pivot; the xx and zz coordinates are transformed while yy is fixed. This is needed any time 3D data needs to be rotated around the vertical horizontal axis.

How it solves the problem

The xx and zz coordinates form the plane perpendicular to the yy-axis. Rotating this plane by θ\theta gives: x′=xcos⁡θ+zsin⁡θx' = x\cos\theta + z\sin\theta, z′=−xsin⁡θ+zcos⁡θz' = -x\sin\theta + z\cos\theta. The sign pattern differs from the standard 2D rotation because of the right-hand rule: the positive rotation from zz to xx (not xx to zz) defines the positive direction around the yy-axis.

Example in a business

A DS augments a drone image dataset by applying pitch rotations: X_augmented = X @ R2(theta).T for random θ∈[−10°,10°]\theta \in [-10°, 10°]. This prevents an object detection model from failing when the camera is slightly tilted up or down.

The formula, piece by piece

  • R2(θ)R_2(\theta): 3×33\times3 rotation matrix around the e2=(0,1,0)e_2 = (0,1,0) axis (y-axis)
  • Row 1 = (cos⁡θ,0,sin⁡θ)(\cos\theta, 0, \sin\theta): new x is xcos⁡θ+zsin⁡θx\cos\theta + z\sin\theta
  • Row 2 = (0,1,0)(0, 1, 0): y-coordinate is unchanged
  • Row 3 = (−sin⁡θ,0,cos⁡θ)(-\sin\theta, 0, \cos\theta): new z is −xsin⁡θ+zcos⁡θ-x\sin\theta + z\cos\theta
  • Sign flip: R2R_2 has +sin⁡θ+\sin\theta in position (1,3) and −sin⁡θ-\sin\theta in position (3,1) — opposite to R1R_1 and R3R_3
  • R2(0)=I3R_2(0) = I_3. R2(−θ)=R2(θ)T=R2(θ)−1R_2(-\theta) = R_2(\theta)^T = R_2(\theta)^{-1}
  • det⁡(R2)=1\det(R_2) = 1 (proper rotation)

The formula in words

"Lock the y-axis. In the xz-plane, apply a rotation: x and z exchange contributions with sine and cosine. But the sign of sine is swapped compared to R1R_1 and R3R_3 due to the right-hand rule around the y-axis." Tiny example: θ=90°\theta = 90°, v=(1,0,0)v = (1, 0, 0) (x-axis unit vector). R2(90°)v=(cos⁡90°,0,−sin⁡90°)=(0,0,−1)R_2(90°)v = (\cos90°, 0, -\sin90°) = (0, 0, -1). After rotating 90° around y, the positive x-axis maps to the negative z-axis. ✓\checkmark (right-hand rule)

Critical Concepts

  • Sign anomaly: in R2R_2, the +sin⁡θ+\sin\theta is in the top-right and −sin⁡θ-\sin\theta is in the bottom-left. In R1R_1 and R3R_3, it is reversed (−sin⁡θ-\sin\theta top-right, +sin⁡θ+\sin\theta bottom-left). This is not a typo — it follows the right-hand rule.
  • Mnemonic: R1R_1 rotates yz, R2R_2 rotates xz (with flipped signs), R3R_3 rotates xy.
  • Orthogonal: R2TR2=IR_2^T R_2 = I, det⁡(R2)=1\det(R_2) = 1.
  • Composition: Euler angles: R(ψ,ϕ,θ)=R3(ψ)R2(ϕ)R1(θ)R(\psi, \phi, \theta) = R_3(\psi) R_2(\phi) R_1(\theta) (yaw, pitch, roll).
  • Gimbal lock: when ϕ=±90°\phi = \pm90°, the yaw and roll axes align and one degree of freedom is lost.

Use quaternions for robust 3D orientation representation.

Step-by-step calculation (tiny example)

Step 1: Build the rotation matrix for θ=30°\theta = 30° cos⁡30°=3/2≈0.866\cos30° = \sqrt{3}/2 \approx 0.866, sin⁡30°=0.5\sin30° = 0.5. R2(30°)=(0.86600.5010−0.500.866)R_2(30°) = \begin{pmatrix}0.866 & 0 & 0.5\\ 0 & 1 & 0\\ -0.5 & 0 & 0.866\end{pmatrix}.

Step 2: Apply to v=(1,2,3)Tv = (1, 2, 3)^T x′=0.866⋅1+0.5⋅3=0.866+1.5=2.366x' = 0.866\cdot1 + 0.5\cdot3 = 0.866+1.5 = 2.366. y′=2y' = 2 (unchanged). z′=−0.5⋅1+0.866⋅3=−0.5+2.598=2.098z' = -0.5\cdot1 + 0.866\cdot3 = -0.5+2.598 = 2.098.

Step 3: Verify length preservation ∥v∥=1+4+9=14\|v\| = \sqrt{1+4+9} = \sqrt{14}. ∥R2v∥=2.3662+4+2.0982=5.598+4+4.402=14\|R_2 v\| = \sqrt{2.366^2+4+2.098^2} = \sqrt{5.598+4+4.402} = \sqrt{14}. ✓\checkmark

Code examples

Beginner example (Python)

python
import numpy as np

# -- Rotation matrix R2(theta) around the y-axis ---


def rotation_y(theta_deg: float) -> np.ndarray:
    """Return 3x3 rotation matrix for rotation around y-axis by theta_deg degrees."""
    theta = np.radians(theta_deg)
    c, s = np.cos(theta), np.sin(theta)
    return np.array([
        [ c, 0.0, s],
        [0.0, 1.0, 0.0],
        [-s, 0.0, c],
    ])


v = np.array([1.0, 0.0, 0.0])  # unit x vector
for angle in [0, 30, 90, 180]:
    R2 = rotation_y(angle)
    v_rot = R2 @ v
    print(f"theta={angle:3d}°: {v} -> {v_rot.round(4)}")


# Verify sign pattern vs R1
def rotation_x(theta_deg):
    t = np.radians(theta_deg)
    return np.array([[1, 0, 0], [0, np.cos(t), -np.sin(t)], [0, np.sin(t), np.cos(t)]])


print(f"\nR2(45) sin pattern (note flipped signs vs R1):")
print(rotation_y(45).round(3))
print(f"\nR1(45) for comparison:")
print(rotation_x(45).round(3))

# Verify orthogonality
R2 = rotation_y(37)
print(f"\nR2^T R2 = I: {np.allclose(R2.T @ R2, np.eye(3))}")
print(f"det(R2) = 1: {np.isclose(np.linalg.det(R2), 1.0)}")

Beginner example (R)

r
# -- Rotation around y-axis ---
rotation_y <- function(theta_deg) {
  t <- theta_deg * pi / 180
  matrix(c(cos(t), 0, -sin(t), 0, 1, 0, sin(t), 0, cos(t)), nrow=3, ncol=3, byrow=TRUE)
}
v <- c(1, 2, 3)
for (angle in c(0, 30, 90, 180)) {
  R2 <- rotation_y(angle)
  v_rot <- R2 %*% v
  cat(sprintf("theta=%d: (%.4f, %.4f, %.4f) norm=%.4f\n", angle, v_rot[1], v_rot[2], v_rot[3], sqrt(sum(v_rot^2))))
}

Professional example (Python)

python
import numpy as np
import pandas as pd
np.random.seed(42)

# -- Business scenario: Euler angle composition ---
# Compose yaw (R3), pitch (R2), roll (R1) for full 3D orientation.
# Simulate sensor orientation for an autonomous vehicle dataset.


def rotation_x(theta_deg):
    t = np.radians(theta_deg)
    c, s = np.cos(t), np.sin(t)
    return np.array([[1, 0, 0], [0, c, -s], [0, s, c]])


def rotation_y(theta_deg):
    t = np.radians(theta_deg)
    c, s = np.cos(t), np.sin(t)
    return np.array([[c, 0, s], [0, 1, 0], [-s, 0, c]])


def rotation_z(theta_deg):
    t = np.radians(theta_deg)
    c, s = np.cos(t), np.sin(t)
    return np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]])


N_SENSORS = 20
sensors = []
for i in range(N_SENSORS):
    yaw = np.random.uniform(-180, 180)  # rotation around z (heading)
    pitch = np.random.uniform(-15, 15)  # rotation around y (tilt)
    roll = np.random.uniform(-10, 10)   # rotation around x (lean)

    # Full rotation: R = R3(yaw) R2(pitch) R1(roll)
    R = rotation_z(yaw) @ rotation_y(pitch) @ rotation_x(roll)

    # Verify it is a valid rotation matrix
    is_ortho = np.allclose(R.T @ R, np.eye(3))
    det_ok = np.isclose(np.linalg.det(R), 1.0)
    sensors.append({
        "sensor_id": i + 1,
        "yaw_deg": round(yaw, 1),
        "pitch_deg": round(pitch, 1),
        "roll_deg": round(roll, 1),
        "is_valid_rotation": is_ortho and det_ok,
    })
df = pd.DataFrame(sensors)
print("Euler angle composition (R = R3(yaw) @ R2(pitch) @ R1(roll)):")
print(df.to_string(index=False))
print(f"\nAll valid rotations: {df['is_valid_rotation'].all()}")

Source: MML1

#linear-algebra#spatial-distance-norms-and-analytic-geometry#3d-rotations

Keyboard shortcuts

Single keys, ignored while typing in a field or with Cmd, Ctrl or Alt held.

0
Home
1 2 3 4
Work, Writing, Tools, About
j / k
Next / previous section on this page
n / p
Next / previous project or essay
u
Up one level
l
Deutsch
t
Light or dark theme
?
This list
Esc
Close