Files
2nd/10_Wiki/Topics/Computer_Science_and_Theory/Gimbals-and-Orientation.md
T
Antigravity Agent f8b21af4be Wiki cleanup: error-doc removal, dedup merge, link normalization
10_Wiki/Topics 대규모 정리:
- 오류 캡처/미완성 stub 문서 227개 제거
- 교차폴더 중복 43클러스터 병합 (63파일 → redirect)
- 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건
- 카테고리 MOC 6개 신규 생성
- Graph 섹션 미해결 related-keyword 링크 10,058건 제거

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 23:52:15 +09:00

5.5 KiB
Raw Blame History

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-gimbals-and-orientation Gimbals and Orientation 10_Wiki/Topics verified self
Gimbal Lock
3D Orientation
Rotation Representation
none A 0.92 applied
graphics
math
rotation
quaternion
robotics
2026-05-10 pending
language framework
Python NumPy/SciPy

Gimbals and Orientation

매 한 줄

"매 3D rotation은 representation 의 선택이 다 — Euler 직관, quaternion 안전, matrix 합성 빠르". Gimbal lock 의 1958 Apollo IMU에서 발견된 singularity 매 모든 3-axis Euler systems에서 발생, 매 quaternion / rotation matrix 의 modern solution. 매 robotics, graphics, aerospace, VR 의 fundamental.

매 핵심

매 representations

  • Euler angles (roll, pitch, yaw): 3 floats, intuitive, but gimbal lock at ±90° pitch.
  • Rotation matrix (3×3): 9 floats, no singularity, composable via multiplication, but redundant (only 3 DOF).
  • Quaternion (w, x, y, z): 4 floats, no gimbal lock, smooth SLERP interpolation, double cover (q and -q same rotation).
  • Axis-angle (Rodrigues): 3 floats encoding axis × angle, compact.

매 gimbal lock 매커니즘

  • 매 3 nested rotations (e.g. ZYX) 매 second rotation이 ±90° 면 first/third axis가 align — DOF loss from 3 to 2.
  • 매 Apollo 11 LM 의 famous near-miss: Aldrin manually steered to avoid IMU lock.

매 응용

  1. Robotics IK / joint orientation.
  2. Game character / camera control.
  3. VR/AR head tracking (IMU sensor fusion).
  4. Drone / aerospace attitude control.
  5. Skeletal animation blending.

💻 패턴

Quaternion from Euler (avoid gimbal lock)

import numpy as np

def euler_to_quat(roll, pitch, yaw):
    cr, sr = np.cos(roll/2),  np.sin(roll/2)
    cp, sp = np.cos(pitch/2), np.sin(pitch/2)
    cy, sy = np.cos(yaw/2),   np.sin(yaw/2)
    w = cr*cp*cy + sr*sp*sy
    x = sr*cp*cy - cr*sp*sy
    y = cr*sp*cy + sr*cp*sy
    z = cr*cp*sy - sr*sp*cy
    return np.array([w, x, y, z])

SLERP (smooth quaternion interpolation)

def slerp(q0, q1, t):
    dot = np.dot(q0, q1)
    if dot < 0.0:
        q1, dot = -q1, -dot
    if dot > 0.9995:
        return (q0 + t*(q1-q0)) / np.linalg.norm(q0 + t*(q1-q0))
    theta_0 = np.arccos(dot)
    theta = theta_0 * t
    s0 = np.cos(theta) - dot * np.sin(theta) / np.sin(theta_0)
    s1 = np.sin(theta) / np.sin(theta_0)
    return s0*q0 + s1*q1

Rotation matrix composition

from scipy.spatial.transform import Rotation as R

R1 = R.from_euler('xyz', [30, 45, 60], degrees=True)
R2 = R.from_quat([0, 0, 0.707, 0.707])  # x,y,z,w
R_combined = R2 * R1
print(R_combined.as_matrix())

Axis-angle (Rodrigues' formula)

def rodrigues(axis, theta):
    axis = axis / np.linalg.norm(axis)
    K = np.array([[ 0, -axis[2], axis[1]],
                  [ axis[2], 0, -axis[0]],
                  [-axis[1], axis[0], 0]])
    return np.eye(3) + np.sin(theta)*K + (1-np.cos(theta))*K@K

IMU sensor fusion (complementary filter)

def imu_update(q, gyro, accel, dt, alpha=0.98):
    # gyro integration
    omega = np.array([0, *gyro])
    q_dot = 0.5 * quat_mul(q, omega)
    q_gyro = q + q_dot * dt
    q_gyro /= np.linalg.norm(q_gyro)
    # accel correction
    q_accel = accel_to_quat(accel)
    return slerp(q_accel, q_gyro, alpha)

Detect gimbal lock

def detect_lock(euler_pitch, threshold=89.5):
    return abs(euler_pitch) > threshold  # near ±90°

Quaternion → Rotation matrix

def quat_to_matrix(q):
    w, x, y, z = q
    return np.array([
        [1-2*(y*y+z*z), 2*(x*y-z*w),   2*(x*z+y*w)],
        [2*(x*y+z*w),   1-2*(x*x+z*z), 2*(y*z-x*w)],
        [2*(x*z-y*w),   2*(y*z+x*w),   1-2*(x*x+y*y)]
    ])

매 결정 기준

상황 Approach
User-facing UI sliders Euler (intuitive)
3D engine internal Quaternion
Skeletal animation blending Quaternion + SLERP
Physics / forces composition Rotation matrix
IMU streaming Quaternion + complementary/Kalman
Compact storage Axis-angle or compressed quat

기본값: Quaternion internally, Euler at user boundaries.

🔗 Graph

🤖 LLM 활용

언제: orientation representation 의 conversion code 생성, gimbal lock debugging hints, sensor fusion math derivation. 언제 X: real-time IMU loop (latency critical — use compiled code), safety-critical aerospace code (require formal verification).

안티패턴

  • Storing rotation as Euler: gimbal lock + interpolation discontinuity. Store as quaternion.
  • Linear interpolation of quaternions: NLERP works로컬 but SLERP for accuracy. NLERP for speed in animation.
  • Forgetting double cover: q and -q same rotation; SLERP needs sign check.
  • Gradient-based optimization on Euler: discontinuous near singularities — use quaternion or matrix tangent space.
  • Mixing conventions: (w,x,y,z) vs (x,y,z,w), intrinsic vs extrinsic Euler — document explicitly.

🧪 검증 / 중복

  • Verified (Shoemake 1985 quaternion paper, NASA Apollo IMU records, scipy.spatial.transform docs).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — full content with quaternion/Euler/matrix patterns + IMU fusion