API Reference

orientation_kinematics.core

Object-oriented core math for orientation_kinematics kinematics (SO(3)).

This module defines four primary classes:

  • AxisAngle : φ about unit axis û (Rodrigues / Euler axis–angle)

  • RodriguesVector : w = û * tan(φ/2)

  • Quaternion : unit quaternion (Euler parameters) [e0, e1, e2, e3] (scalar-first)

  • SO3 : rotation_kinematics group element with a 3x3 matrix representation

All classes are immutable-ish (dataclasses with tuples/np arrays) and provide clear conversion methods so they are easy to unit-test.

Numerical notes

  • Conversions handle near-zero and near-π angles with safe branches.

  • All inputs are not assumed normalized; constructors normalize internally.

  • Tolerances controlled by EPS and use of np.clip to keep values in domain.

References (matching book equations)

Axis-angle ↔ matrix : Eqs. 3.3–3.7, 3.10–3.16 Matrix → axis-angle : Eqs. 3.10–3.11, 3.17–3.18 Euler parameters (quat) ↔ matrix : Eq. 3.140 and companions Rodrigues vector : Eqs. 3.201–3.206 Exponential map : Eq. 3.187 (handled in utils.expm_so3)

Author: Robotics project

class orientation_kinematics.core.AxisAngle(phi: float, u: ndarray)[source]

Axis–angle (Rodrigues) representation.

Parameters:
  • phi (float) – Rotation angle (radians). Can be outside [-π, π]; stored unchanged.

  • u (np.ndarray) – 3-vector; need not be unit. Will be normalized internally.

as_matrix() → np.ndarray[source]
to_quaternion() → Quaternion[source]
to_rodrigues() → RodriguesVector[source]
compose(other: AxisAngle) → SO3[source]
static from_matrix(R: np.ndarray) -> AxisAngle
as_matrix() → ndarray[source]
compose(other: AxisAngle) → SO3[source]

Return SO3 representing R_other * R_self.

static from_matrix(R: ndarray) → AxisAngle[source]
phi: float
to_quaternion() → Quaternion[source]
to_rodrigues() → RodriguesVector[source]
u: ndarray
class orientation_kinematics.core.Quaternion(e0: float, e1: float, e2: float, e3: float)[source]

Unit quaternion (Euler parameters) with scalar-first storage.

Fields

e0 : float e1, e2, e3 : float (vector part)

normalized(), conj(), as_matrix(), rotate(v), multiply(q)[source]
to_axis_angle(), to_rodrigues()[source]
class from_matrix(R), from_axis_angle(phi, u)
as_matrix() → ndarray[source]
as_np() → ndarray[source]
conj() → Quaternion[source]
e0: float
e1: float
e2: float
e3: float
static from_axis_angle(phi: float, u: ndarray) → Quaternion[source]
static from_matrix(R: ndarray) → Quaternion[source]

Robust matrix → quaternion (scalar-first).

multiply(q: Quaternion) → Quaternion[source]
norm() → float[source]
normalized() → Quaternion[source]
rotate(v: ndarray) → ndarray[source]

Rotate a 3-vector by this quaternion.

to_axis_angle() → AxisAngle[source]
to_rodrigues() → RodriguesVector[source]
class orientation_kinematics.core.RodriguesVector(w: ndarray)[source]

Rodrigues vector w = û tan(φ/2). Compact axis–angle container.

as_matrix() → np.ndarray[source]
to_axis_angle() → AxisAngle[source]
to_quaternion() → Quaternion[source]
as_matrix() → ndarray[source]
to_axis_angle() → AxisAngle[source]
to_quaternion() → Quaternion[source]
w: ndarray
class orientation_kinematics.core.SO3(R: ndarray)[source]

SO(3) rotation_kinematics class with a 3×3 matrix representation.

Construct directly from a 3×3 (validated and projected), or use the convenience constructors.

compose(other) → SO3[source]
inverse_kinematics() → SO3
act(v) → np.ndarray[source]
angle() → float[source]
axis() → np.ndarray[source]
to_axis_angle() / to_quaternion() / to_rodrigues()[source]
class from_axis_angle(phi, u)
class from_quaternion(q)
class from_rodrigues(w)
identity()[source]
R: ndarray
act(v: ndarray) → ndarray[source]
angle() → float[source]
axis() → ndarray[source]
compose(other: SO3) → SO3[source]

Return self * other (apply ‘other’ then ‘self’).

static from_axis_angle(phi: float, u: ndarray) → SO3[source]
static from_quaternion(q: Quaternion) → SO3[source]
static from_rodrigues(w: ndarray | RodriguesVector) → SO3[source]
static identity() → SO3[source]
inverse() → SO3[source]
to_axis_angle() → AxisAngle[source]
to_quaternion() → Quaternion[source]
to_rodrigues() → RodriguesVector[source]

orientation_kinematics.utils (OO version)

Object-oriented utilities for SO(3) math used across the orientation_kinematics package.

Design

  • NumericConfig: central place to configure tolerances, backend preferences.

  • OrientationUtils: instance providing methods (normalize, skew, vex, vers, safe_acos, project_to_so3, expm_so3, levi_civita).

  • A default singleton UTILS is exported, and thin module-level functions delegate to it for backward compatibility and convenience in tests.

This keeps code testable and mockable:
  • swap UTILS with a custom instance (e.g., different EPS)

  • inject a fake backend (disable SciPy, etc.)

Author: Robotics project

class orientation_kinematics.utils.NumericConfig(eps: float = 1e-12, prefer_scipy: bool = True)[source]

Configuration for numeric utilities.

eps

Tolerance used throughout (zero checks, comparisons).

Type:

float

prefer_scipy

If True and SciPy is available, use SciPy’s expm for exp_so3.

Type:

bool

eps: float = 1e-12
prefer_scipy: bool = True
class orientation_kinematics.utils.OrientationUtils(config: NumericConfig | None = None)[source]

OO facade for common SO(3) utility routines.

The methods are instance methods to allow dependency injection and per-instance configuration during tests (e.g., custom EPS).

property EPS: float
expm_so3(omega: ndarray) → ndarray[source]

Compute exp(omega^) ∈ SO(3).

If SciPy’s expm is available and allowed, uses it; otherwise, falls back to the closed-form Rodrigues formula (stable and fast).

levi_civita() → ndarray[source]

Return the Levi–Civita symbol ε_ijk as a 3×3×3 tensor.

normalize(v: ndarray) → ndarray[source]

Return v normalized; if ||v|| < eps, return v unchanged.

project_to_so3(R: ndarray) → ndarray[source]

Project a near-rotation_kinematics to SO(3) via SVD (closest in Frobenius norm).

safe_acos(x: float) → float[source]

Clamp into [-1, 1] before arccos (returns radians in [0, π]).

skew(v: ndarray) → ndarray[source]

Skew-symmetric (hat) operator for a 3-vector.

vers(phi: float) → float[source]

Versine: 1 - cos(phi).

vex(S: ndarray) → ndarray[source]

Vee operator (inverse_kinematics hat) for a 3×3 skew matrix.

orientation_kinematics.utils.expm_so3(omega: ndarray) → ndarray[source]
orientation_kinematics.utils.levi_civita() → ndarray[source]
orientation_kinematics.utils.normalize(v: ndarray) → ndarray[source]
orientation_kinematics.utils.project_to_so3(R: ndarray) → ndarray[source]
orientation_kinematics.utils.safe_acos(x: float) → float[source]
orientation_kinematics.utils.skew(v: ndarray) → ndarray[source]
orientation_kinematics.utils.vers(phi: float) → float[source]
orientation_kinematics.utils.vex(S: ndarray) → ndarray[source]

orientation_kinematics.io (OO version)

Object-oriented I/O utilities for the orientation_kinematics package.

Design

  • PathConfig: holds the canonical input/output directory layout.

  • IOManager: high-level read/write facade (JSON and CSV matrices).

  • A default singleton IO is exported, along with thin shims read_json, write_json, write_matrix_csv etc., for convenience and compatibility.

Security

  • All writes create parent directories as needed.

  • Filenames are validated to remain under the configured in/out dirs (prevents path_planning traversal).

Author: Robotics project

class orientation_kinematics.io.IOManager(config: PathConfig | None = None)[source]

High-level, testable I/O facade for JSON and CSV matrices.

read_jobs(name: str) → list[dict][source]

Read a batch jobs file (JSON list) from in/.

read_json(name: str) → dict[source]

Read JSON from in/ if present; otherwise fall back to out/.

read_matrix_csv(name: str) → ndarray[source]

Read a CSV from in/ or out/ (prefers in/), returning np.ndarray.

write_json(name: str, data: dict) → None[source]

Write JSON to out/ by filename.

write_matrix_csv(name: str, M: ndarray) → None[source]

Write a 2D numpy array as CSV into out/.

write_results(name: str, results: list[dict]) → None[source]

Write batch results JSON to out/.

class orientation_kinematics.io.PathConfig(base_dir: Path, in_subdir: str = 'in', out_subdir: str = 'out')[source]

Directory layout for the app.

Parameters:
  • base_dir (Path) – The directory containing the orientation_kinematics package files.

  • in_subdir (str) – Subdirectory (relative to base_dir) for inputs.

  • out_subdir (str) – Subdirectory (relative to base_dir) for outputs.

base_dir: Path
property in_dir: Path
in_subdir: str = 'in'
property out_dir: Path
out_subdir: str = 'out'
orientation_kinematics.io.read_json(name: str) → dict[source]
orientation_kinematics.io.read_matrix_csv(name: str) → ndarray[source]
orientation_kinematics.io.write_json(name: str, data: dict) → None[source]
orientation_kinematics.io.write_matrix_csv(name: str, M: ndarray) → None[source]

orientation_kinematics.design (OO version)

Object-oriented class diagram generator for the orientation_kinematics package.

Design

  • DiagramConfig: configuration (targets, output directory, filters)

  • ClassIntrospector: discover classes & relationships from modules

  • DiagramBuilder (abstract): pluggable emitters

  • MermaidBuilder / GraphvizBuilder: concrete emitters

  • DiagramGenerator: orchestrates introspection + emit to files

Outputs

  • Graphviz DOT : <out_dir>/class_diagram.dot

  • Mermaid (mmd) : <out_dir>/class_diagram.mmd

class orientation_kinematics.design.ClassInfo(name: 'str', module: 'str', annotations: 'Dict[str, str]')[source]
annotations: Dict[str, str]
module: str
name: str
class orientation_kinematics.design.ClassIntrospector(config: DiagramConfig)[source]

Find classes and simple relationships using type annotations.

collect() → Tuple[List[ClassInfo], List[Relationship]][source]
class orientation_kinematics.design.DiagramBuilder[source]

Abstract diagram emitter.

build(classes: List[ClassInfo], rels: List[Relationship]) → str[source]
class orientation_kinematics.design.DiagramConfig(out_dir: ~pathlib.Path, modules: ~typing.Sequence[~types.ModuleType], include_prefixes: ~typing.Sequence[str] = <factory>, exclude_class_names: ~typing.Sequence[str] = <factory>)[source]

Configuration for class diagram generation.

exclude_class_names: Sequence[str]
include_prefixes: Sequence[str]
modules: Sequence[ModuleType]
out_dir: Path
should_include_class(cls: type) → bool[source]
should_include_module(module_name: str) → bool[source]
class orientation_kinematics.design.DiagramGenerator(config: DiagramConfig, *, builders: List[Tuple[str, DiagramBuilder]] | None = None)[source]

High-level generator to emit multiple diagram formats to disk.

generate() → List[Path][source]
class orientation_kinematics.design.GraphvizBuilder[source]

Render to Graphviz DOT with record-shaped nodes.

build(classes: List[ClassInfo], rels: List[Relationship]) → str[source]
class orientation_kinematics.design.MermaidBuilder[source]

Render to Mermaid classDiagram syntax.

build(classes: List[ClassInfo], rels: List[Relationship]) → str[source]
class orientation_kinematics.design.Relationship(a: 'str', b: 'str', kind: 'str' = 'association')[source]
a: str
b: str
kind: str = 'association'
orientation_kinematics.design.generate_diagram(out_dir: Path) → Tuple[Path, Path][source]

Generate both DOT and Mermaid diagrams for orientation_kinematics.core.