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.
- to_quaternion() Quaternion[source]¶
- to_rodrigues() RodriguesVector[source]¶
- static from_matrix(R: np.ndarray) -> AxisAngle
- 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)
- class from_matrix(R), from_axis_angle(phi, u)
- 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]¶
- normalized() Quaternion[source]¶
- to_rodrigues() RodriguesVector[source]¶
- class orientation_kinematics.core.RodriguesVector(w: ndarray)[source]¶
Rodrigues vector w = û tan(φ/2). Compact axis–angle container.
- to_quaternion() Quaternion[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.
- class from_axis_angle(phi, u)
- class from_quaternion(q)
- class from_rodrigues(w)
- R: ndarray¶
- static from_quaternion(q: Quaternion) SO3[source]¶
- static from_rodrigues(w: ndarray | RodriguesVector) SO3[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).
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.
- 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.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¶
- 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.
- 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]¶