_______ _            _____                     _ _             _         _____           _
 |__   __| |          / ____|                   | (_)           | |       / ____|         | |
    | |  | |__   ___ | |     ___   ___  _ __ __| |_ _ __   __ _| |_ ___ | (___  _   _ ___| |_ ___ _ __ ___
    | |  | '_ \ / _ \| |    / _ \ / _ \| '__/ _` | | '_ \ / _` | __/ _ \ \___ \| | | / __| __/ _ \ '_ ` _ \
    | |  | | | |  __/| |___| (_) | (_) | | | (_| | | | | | (_| | ||  __/ ____) | |_| \__ \ ||  __/ | | | | |
    |_|  |_| |_|\___| \_____\___/ \___/|_|  \__,_|_|_| |_|\__,_|\__\___||_____/ \__, |___/\__\___|_| |_| |_|
                                                                                 __/ |
                                                                                |___/
🌍 Language | 语言选择
The Coordinate System (Coord) Framework provides an intuitive and powerful solution for coordinate transformations in 3D space. At its core, it simplifies complex coordinate operations by treating coordinate systems as first-class algebraic objects that support arithmetic operations like multiplication and division.
The framework now features the revolutionary Intrinsic Gradient Operator (内禀梯度算子) method for curvature computation, achieving < 0.001% error on test surfaces - a 2000x improvement over traditional methods. This breakthrough transforms abstract differential geometry into simple coordinate system change analysis.
- 🔄 Intuitive Coordinate Transformations: World ↔ Local coordinate conversions with simple operators
 - 🏗️ Hierarchical Systems: Efficient multi-node transformations for robotics and graphics
 - 🎯 Algebraic Operations: Coordinate systems as mathematical objects supporting +, -, *, /
 - ⚡ High Performance: Optimized for real-time applications
 - 🧮 Advanced Mathematics: Optional differential geometry capabilities for research
 - 🌐 Multi-Platform: C++ library with Python bindings
 
The concept of coordinate systems traces back to René Descartes, who sought to use geometry to describe celestial motion. However, his methods lacked the precision required for exact calculations. Long before Descartes, early civilizations already had notions of coordinate-like references—particularly the idea of a "world center."
During the Hellenistic period, Ptolemaic cosmology placed Earth at the center of the universe, while Copernicus later shifted this central reference to the Sun. The key difference between these models was not just the choice of origin but the mathematical framework they enabled. By repositioning the center at the Sun, scientists recognized the need for a dynamic, motion-based mathematical-physical system.
Thus, the choice of coordinate system profoundly influences both worldview and computational paradigms. Einstein's relativity theory, for instance, can be viewed as a consequence of extending coordinates from flat Euclidean space to curved manifolds.
If we study differential geometry, at the level of differential elements, the coordinate system can be linearized. In this way, a concept of a certain universal coordinate system object can be formed, serving as a ruler or, alternatively, understood as the dimension of space.
The Coordinate System (or Frame), referred to here as the Coord object, is a mathematical construct rooted in group theory that defines a coordinate system in three-dimensional space. In physics, such a structure is commonly known as a reference frame, while in differential geometry, it is often called a frame field or moving frame.
From a group-theoretic perspective, a coordinate system can be treated as an algebraic object capable of participating in group operations. The Coord object unifies these concepts, allowing both coordinate systems and individual coordinates to serve as elements in algebraic operations, such as multiplication and division.
By extending coordinate systems with arithmetic operations, the Coord object enables direct coordinate transformations, eliminating the need for complex matrix manipulations. This approach provides an intuitive geometric interpretation and simplifies coordinate system operations for practical applications.
┌─────────────────┐
│    coord3       │  ← Full coordinate system (position + rotation + scaling)
│  (Complete)     │
├─────────────────┤
│    vcoord3      │  ← Vector coordinate system (rotation + scaling)
│  (Scaling)      │
├─────────────────┤
│    ucoord3      │  ← Unit coordinate system (rotation only)
│  (Rotation)     │
└─────────────────┘In C++, a coordinate system in three-dimensional space is defined by an origin, three directional axes, and three scaling components as follows:
struct coord {
    vec3 ux, uy, uz;   // Three basis vectors
    vec3 s;            // Scaling
    vec3 o;            // Origin
};A coordinate system can be constructed using three axes or Euler angles as follows:
coord C1(vec3 o);                    // Position only
coord C2(vec3 ux, vec3 uy, vec3 uz); // From basis vectors
coord C3(vec3 o, vec3 s, quat q);    // Complete: position, scale, rotation- Composition (*): 
C₃ = C₂ ∘ C₁- Sequential transformations - Relative (/): 
R = C₁ · C₂⁻¹- Relative transformation - Inverse (%): 
R = C₁⁻¹ · C₂- Inverse relative transformation 
The fundamental operations for coordinate transformations:
Transform from local to parent coordinate system:
V0 = V1 * C1    // V1 in local C1 → V0 in parent systemProject from parent to local coordinate system:
V1 = V0 / C1    // V0 in parent → V1 in local C1 system1. World ↔ Local Coordinate Transformations
Convert a vector between world and local coordinate systems:
VL = Vw / C      // World to local
Vw = VL * C      // Local to world2. Multi-Node Hierarchical Systems
Essential for robotics, computer graphics, and complex mechanical systems:
// Forward transformation chain
C = C3 * C2 * C1
Vw = VL * C
// Reverse transformation chain
VL = Vw / C
V4 = V1 / C2 / C3 / C43. Parallel Coordinate System Conversion
Convert between coordinate systems that share the same parent:
C0 { C1, C2 }    // C1 and C2 are both children of C0
V2 = V1 * C1 / C2 // Convert from C1 space to C2 space4. Advanced Operations
Scalar multiplication:
C * k = {C.o, C.s * k, C.u}
where: C.u = {C.ux, C.uy, C.uz}Quaternion operations:
C0 = C1 * q1     // Apply quaternion rotation
C1 = C0 / q1     // Remove quaternion rotation
q0 = q1 * C1     // Extract quaternion from coordinate system
q1 = q0 / C1     // Relative quaternionVector addition:
C2 = C1 + o      // Translate coordinate system
Where C2 = {C1.o + o, C1.v}, C1.v = {C1.ux*C1.s.x, C1.uy*C1.s.y, C1.uz*C1.s.z}- 3D Scene Graphs: Efficient parent-child transformations
 - Character Animation: Bone hierarchies and skeletal animation
 - Camera Systems: View and projection matrix management
 - Object Positioning: Intuitive placement and orientation
 
- Forward/Inverse Kinematics: Joint chain calculations
 - Multi-Arm Coordination: Relative positioning between robot arms
 - SLAM Systems: Map coordinate transformations
 - Path Planning: Coordinate space navigation
 
- Assembly Systems: Component positioning and constraints
 - Mechanical Design: Part relationships and tolerances
 - Manufacturing: Tool path coordinate transformations
 - Simulation: Physical system coordinate management
 
- Player Movement: Character controller transformations
 - Physics Systems: Collision detection coordinate spaces
 - UI Systems: Screen to world coordinate conversions
 - Networking: Synchronized coordinate systems
 
#include "com.hpp"
#include "vector.hpp"
#include "quaternion.hpp"
#include "coord.hpp"
int main() {
    // Create coordinate systems
    coord3 world;                    // World coordinate system
    coord3 robot(0, 0, 1);          // Robot at position (0,0,1)
    coord3 arm = coord3::from_eulers(45, 0, 0); // Arm rotated 45° around X
    // Create transformation chain
    coord3 arm_in_world = robot * arm;
    // Transform a point from arm space to world space
    vec3 point_in_arm(1, 0, 0);     // Point in arm coordinate system
    vec3 point_in_world = point_in_arm * arm_in_world;
    // Convert back from world to arm space
    vec3 converted_back = point_in_world / arm_in_world;
    return 0;
}// Robot arm with multiple joints
coord3 base;
coord3 shoulder(0, 0, 0.5);        // Shoulder joint
coord3 elbow(0, 0, 0.3);           // Elbow joint
coord3 wrist(0, 0, 0.2);           // Wrist joint
// Create transformation chain
coord3 full_transform = base * shoulder * elbow * wrist;
// Point at end effector
vec3 end_point(0, 0, 0.1);
vec3 world_position = end_point * full_transform;
// Inverse: find local coordinates given world position
vec3 local_coords = world_position / full_transform;To compile the C++ version of the coordinate system library:
# Basic compilation
g++ -std=c++17 -I src -o your_program your_program.cpp
# Example compilation and test
g++ -std=c++17 -I src -o test_coord test_coord.cpp
./test_coord
# With optimization for production
g++ -std=c++17 -O3 -I src -o optimized_program your_program.cppTo use the coordinate_system in Python, you can easily install it via pip:
pip install coordinate_systemLatest Version (v2.5.0) includes the Intrinsic Gradient Operator method:
from coordinate_system import vec3, quat, coord3
from coordinate_system import Sphere, IntrinsicGradientCurvatureCalculator
import math
# Basic coordinate transformations
a = coord3(0, 0, 1, 0, 45, 0)  # Position and rotation
b = coord3(1, 0, 0, 45, 0, 0)
a *= b
print(a)
# NEW: Curvature computation using Intrinsic Gradient Operator
sphere = Sphere(radius=1.0)
calc = IntrinsicGradientCurvatureCalculator(sphere, step_size=1e-4)
K = calc.compute_gaussian_curvature(math.pi/4, math.pi/6)
print(f"Gaussian curvature: {K:.8f}")  # Output: 0.99999641 (error < 0.001%)The following sections describe advanced mathematical capabilities for research and specialized applications.
The framework introduces the revolutionary Intrinsic Gradient Operator for differential geometry:
G_μ = (c(u+h) - c(u)) / h / c(u)
Where:
c(u,v): Intrinsic frame field at point (u,v)h: Finite difference step sizeG_μ: Intrinsic gradient operator in direction μ ∈ {u,v}
Geometric Interpretation:
G_μ.ux, G_μ.uy: Rotation and deformation of tangent spaceG_μ.uz: Rate of change of normal vector (∂n/∂μ)G_μ.s: Variation of metric scaling factors
Using the intrinsic gradient operator, we can directly compute the second fundamental form:
L = -G_u.uz · f_u
M = -½(G_u.uz · f_v + G_v.uz · f_u)
N = -G_v.uz · f_v
And the Gaussian curvature:
K = (LN - M²) / det(g)
The framework provides complete Riemann curvature tensor computation through intrinsic gradient operators:
R(∂_u, ∂_v) = [G_u, G_v] - G_[∂_u,∂_v]
Where:
[G_u, G_v] = G_u ∘ G_v - G_v ∘ G_u(Lie bracket/commutator)G_[∂_u,∂_v](Lie derivative term for non-coordinate bases)
Matrix Representation:
R_uv = [
    [R¹₁₁₂  R¹₁₂₂  R¹₁₃₂],   # Tangent space curvature
    [R²₁₁₂  R²₁₂₂  R²₁₃₂],   # Tangent space curvature  
    [R³₁₁₂  R³₁₂₂  R³₁₃₂]    # Normal curvature
]
From the Riemann curvature tensor, we can extract Gaussian Curvature:
K = (R_01 - R_10) / (2 × det(g))
| Curvature Type | Traditional Method | Intrinsic Gradient Method | Speedup | 
|---|---|---|---|
| Gaussian Curvature | O(n⁴) | O(n³) | ~8× | 
| Riemann Tensor | O(n⁶) | O(n³) | ~27× | 
| Full Curvature Analysis | O(n⁶) | O(n³) | ~27× | 
Advanced differential operations for specialized applications:
Gradient:
▽f = (u * df * Cuv) / Dxyz
	Cuv  = {u, v, 0}
    Dxyz = {ux * dx, uy * dy, uz * dz}
Where C is the embedding coordinate system that transforms from parameter space to 3D space.
Divergence:
▽ ∙ F = dF / Dxyz ∙ Ic
	Ic = {ux, uy, uz}
Where g is the metric tensor.
Curl :
▽ x F = dF / Dxyz x Ic
Where n is the unit normal vector.
// Finite connection between frames
G = C2 / C1 - I;Sphere Test Case - validated with intrinsic gradient operator:
- Radius: R = 1.0
 - Gaussian curvature error < 0.001% at all test points
 - Mean curvature error < 0.001%
 - Principal curvatures: k₁ = k₂ = 1/R (exact within machine precision)
 
Torus Test Case - complex surface validation:
- Major radius: R = 3.0, Minor radius: r = 1.0
 - Gaussian curvature matches theoretical values
 - Successfully captures varying curvature across surface
 - Handles both positive and negative curvature regions
 
The framework naturally embeds Lie theory:
- Group Multiplication: SE(3) operations
 - Lie Algebra: Tangent space operations
 - Bracket Operations: 
[C1, C2] = C1*C2 - C2*C1 - Exponential Maps: Algebra to group transformations
 
This project is licensed under the MIT License - see the LICENSE file for details.
https://zenodo.org/records/17480005
- Historical geometry pioneers: Descartes, Gauss, Riemann
 - Modern differential geometry community
 - Open source computational geometry projects
 - All contributors and collaborators
 
The Coord framework provides a unified computational language for:
- Everyday coordinate transformations (primary use case)
 - Hierarchical system management (robotics, graphics)
 - Advanced differential geometry (research applications)
 - Physical reference frames (physics simulations)
 
By treating coordinate systems as algebraic objects, it creates an intuitive syntax that mirrors mathematical reasoning while maintaining computational efficiency. This approach bridges the gap between abstract mathematics and practical implementation, making complex coordinate operations accessible to developers across multiple domains.
🌟 Star this repository if you find it useful!