Skip to content
panguojun edited this page Feb 6, 2025 · 4 revisions

Computable Coordinate Systems Wiki

1. Introduction

Coordinate systems play a crucial role in multiple fields like mathematics, physics, and computer graphics. However, traditional matrix and tensor operations for coordinate system transformations have their drawbacks. Matrices, not designed specifically for this purpose, lead to redundant calculations and are inconvenient to use. Tensors, on the other hand, are highly abstract, making them difficult to master and apply numerically. This project simplifies these operations by introducing the “coord” object.

2. Concept

The concept of coordinate systems and operable coordinates is inspired by the use of a ruler. A ruler has two main functions:

  • Defining and Mapping: We can define a length on a ruler, for example, 1 cm, and map it onto a physical object during the design - to - creation process.
  • Measuring: We use a ruler to measure the length of a physical object. This concept can be extended to measure various physical quantities.

In a one - dimensional scenario, the conversion between ruler - measured values and a universal unit involves multiplication or division.

  • When converting a measured value $v$ on a ruler with a certain unit (e.g., centimeters) to a universal unit: v₀ = v × cm where $v$ is the value read from the ruler, and $v₀$ is the length in the universal unit.
  • When measuring a physical entity's length: v = v₀/cm In multi - dimensional spaces, the multi - dimensional “ruler” is equivalent to a coordinate system.

3. Design

3.1 Coordinate System Structure

In three - dimensional space, the “coord” structure in C++ is composed of the following parts:

  • Origin (o): It serves as the starting point of the coordinate system. All positions within this coordinate system are measured relative to this origin.
  • Unit Basis Vectors (ux, uy, uz): These unit - length vectors determine the directions of the coordinate axes. Each vector points along a specific axis and is used to define the direction of a particular dimension in the coordinate system.
  • Scaling Component (s): This component allows us to scale the distances measured along each axis. For instance, if $s.x = 2$, the distances along the $x$ - axis (represented by ux) will be twice as long as the default.

There are different ways to construct a “coord” object:

  • By Specifying Axes:
    • coord(vec3 ux, vec3 uy, vec3 uz): This creates a coordinate system with the specified $x$, $y$, and $z$ axes.
    • coord(vec3 ux, vec3 uy): It can be used when the third axis can be deduced or set to a default value.
  • By Euler Angles: coord(float pitch, float yaw, float roll) defines the orientation of the coordinate system using Euler angles. Pitch represents the rotation around the $y$ - axis, yaw around the $z$ - axis, and roll around the $x$ - axis. After creating the object in this way, the origin and scaling can be set as required.

3.2 Operations

  • Multiplication:
    • It is used to transform a vector from a local coordinate system to a parent coordinate system and to merge coordinate systems. For example, if $V_1$ is defined in $C_1$ and $V_0$ is in $C_0$: V₀ = V₁ × C₁
    • The multiplication of vectors and coordinate systems is non - commutative, meaning: V × C ≠ C × V
    • The multiplication of two vectors in the context of coordinate systems is defined as: V₁ × V₂ = ONE × C₁ × ONE × C₂ = ONE × C₁ × C₂ where $ONE$ is the unity vector, and it has the properties $V × ONE = V$ and $C × ONE = C$.
  • Division:
    • It is used to project a vector from a parent coordinate system to a local coordinate system. For example, if $V_0$ is in $C_0$ and $V_1$ is in $C_1$: V₁ = V₀/C₁
    • Due to the non - commutativity of multiplication, there are two types of division. Right division (/) is the regular operation, and left division (\) is defined as: C₁\C₂ = 1/C₁ × C₂ It is recommended to use the right - hand - side form (1/C₁ × C₂) to avoid confusion in calculations.
  • Addition and Subtraction:
    • When calculating the difference between two vectors $\Delta V = V_1 - V_2$, if $V_1 = V × C_1$ and $V_2 = V × C_2$: ΔV = V × (C₁ - C₂)
    • Similarly, for addition: V₁ + V₂ = V × (C₁ + C₂)
    • For operations involving different - type objects, the operation structure follows the object on the left - hand side of the operator.

3.3 Application Scenarios

  • Coordinate System Conversion:
    • To convert a vector $V_w$ from world space to a local coordinate system $C$: Vₗ = V_w/C
    • To convert from a local to a world coordinate system: V_W = Vₗ × C
  • Multiple Node Hierarchy: In a hierarchical structure (such as a scene graph in computer graphics), if $V_5$ is defined in the coordinate system of node 5 and we want to obtain the vector in the parent node at the level of node 2: V₂ = V₅ × C₅ × C₄ × C₃ To get back from $V_2$ to $V_5$: V₅ = V₂/C₃/C₄/C₅

4. Advanced Application Scenarios

4.1 Coordinate System Differentiation

A differential coordinate system simplifies the understanding and performance of differentiation operations in space.

  • Gradient: ∇f = U × df × C_u/(I_c × dxyz) where $U$ represents the principal direction of change, $df$ is the amount of change, $C_u$ is the local coordinate system, $dxyz$ is a vector element in the world coordinate system, and $I_c$ is the default world coordinate system. The product $I_c × dxyz$ forms a differential coordinate system. To simplify numerical calculations, a small scaling factor eps is set for the global coordinate system, which allows for approximating operations as linear and ignoring higher - order terms.
  • Divergence: ∇·F = dF/(I_c × dxyz)·I_c
  • Curl: ∇×F = dF/(I_c × dxyz)×I_c The dot product (·) and cross - product (×) operations are defined between vectors and coordinate systems for these calculations.

4.2 Applications in Differential Geometry

  • Vector Movement: In a curved space, if $V_1$ and $V_2$ are vectors at two adjacent points with coordinate systems $C_1$ and $C_2$ respectively: V₂ = V₁ × C₁/C₂ 可以写成 V₂ = V₁ × (C₁/C₂) (为了更清晰展示运算优先级)
  • Exponential Operation of Coordinate Systems: When a coordinate system moves along the arc of a differential space, rotation is usually involved. A coordinate system can be represented as: C = e^Λ(n) where $n = axis × angle$. Using the Taylor series expansion, we can approximate it as: e^Λ(n) ≈ 1 + (n)-... = cos(angle) + sin(angle)×axis This approximation helps in calculating the derivative of rotation during translation.

5. Curvature Calculation

The coordinate system object can convert vectors between natural and curved coordinate systems. In a surface space, when translating a vector along two perpendicular directions ($u$ and $v$), the curvature can be calculated. In the $u - v$ coordinate system, the Riemann curvature tensor's coordinate - equivalent representation is: G_uv = G_u × G_v - G_v × G_u - G_[u, v] where $G_u = C_u/C_0 - 1$, $G_v = C_v/C_0 - 1$, and $G_{[u, v]} = G_u × W_u + G_v × W_v$ ($W = [u, v]$ is the connection vector).

6. Combination with Lie Groups, Lie Algebras

  • Lie Groups: A Lie group has both continuous and group - like properties. The rotation matrix and our coordinate system $C$ can be considered elements of a Lie group. In a Lie group, multiplication represents transformations between elements. For our coordinate systems, the multiplication operation is similar to matrix multiplication, and the identity element $I$ represents the identity transformation. Thus, $C\in{1,()}$, where $()$ is the multiplication operation for coordinate systems.
  • Lie Algebras: Lie algebras help define operations in a more abstract and concise manner. The cross - product of two vectors $v_1$ and $v_2$ in terms of coordinate systems is: v₁ × v₂ = ONE × (C₁ × C₂) The cross - product operation between coordinate systems is defined using Lie algebra brackets: [C₁, C₂] = C₁ × C₂ - C₂ × C₁

7. Code Implementation

Here is a partial C++ code implementation for basic operations on vectors and coordinate systems:

// Multiplication of a vector and a coordinate system
vec3 operator * (const vec3& p, const coord3& c) 
{ 
    return c.ux * (c.s.x * p.x) + c.uy * (c.s.y * p.y) + c.uz * (c.s.z * p.z) + c.o; 
} 

// Multiplication of two coordinate systems
coord3 operator * (const coord3& c1, const coord3& c2) 
{ 
    coord3 rc; 
    rc.ux = c1.ux.x * c2.ux + c1.ux.y * c2.uy + c1.ux.z * c2.uz; 
    rc.uy = c1.uy.x * c2.ux + c1.uy.y * c2.uy + c1.uy.z * c2.uz; 
    rc.uz = c1.uz.x * c2.ux + c1.uz.y * c2.uy + c1.uz.z * c2.uz; 
    rc.s = s * c.s; 
    rc.o = c1.o.x * c2.s.x * c2.ux + c1.o.y * c2.s.y * c2.uy + c1.o.z * c2.s.z * c2.uz + c2.o; 
    return rc; 
} 

// Division of a vector by a coordinate system
vec3 operator / (const vec3& p, const coord3& c) 
{
    vec3 v = p - c.o; 
    return vec3( v.dot(c.ux) / c.s.x, v.dot(c.uy) / c.s.y, v.dot(c.uz) / c.s.z ); 
} 

// Division of two coordinate systems
coord3 operator / (const coord3& c1, const coord3& c2) 
{
    coord3 rc; 
    rc.ux = vec3(c1.ux.dot(c2.ux), c1.ux.dot(c2.uy), c1.ux.dot(c2.uz)); 
    rc.uy = vec3(c1.uy.dot(c2.ux), c1.uy.dot(c2.uy), c1.uy.dot(c2.uz)); 
    rc.uz = vec3(c1.uz.dot(c2.ux), c1.uz.dot(c2.uy), c1.uz.dot(c2.uz)); 
    rc.s = c1.s / c2.s; 
    rc.o = c1.o - c2.o; 
    rc.o = vec3(rc.o.dot(c2.ux) / c2.s.x, rc.o.dot(c2.uy) / c2.s.y, rc.o.dot(c2.uz) / c2.s.z); 
    return rc; 
} 

// Addition of two coordinate systems
coord3 operator + (const coord3& c1, const coord3& c2) 
{ 
    coord3 rc; 
    rc.ux = c1.VX() + c2.VX(); 
    rc.uy = c1.VY() + c2.VY(); 
    rc.uz = c1.VZ() + c2.VZ();
    rc.norm(); 
    rc.o = o + c2.o; 
    return rc; 
} 

// Subtraction of two coordinate systems
coord3 operator - (const coord3& c1, const coord3& c2) 
{ 
    coord3 rc; 
    rc.ux = c1.VX() - c2.VX(); 
    rc.uy = c1.VY() - c2.VY(); 
    rc.uz = c1.VZ() - c2.VZ(); 
    rc.norm(); 
    rc.o = o - c2.o; 
    return rc; 
}

8. Summary

This project simplifies coordinate system operations by introducing the “coord” object, which overcomes the limitations of traditional matrix and tensor operations. The “coord” structure and its operations provide an efficient way to handle coordinate system transformations. Advanced application scenarios, such as coordinate system differentiation and applications in differential geometry, expand its functionality. The combination with Lie groups and Lie algebras offers a more comprehensive and unified approach to mathematical operations related to coordinate systems. The provided C++ code implementation serves as a practical starting point for real - world applications, facilitating the management of vectors, matrices, and tensors in scenarios involving numerous linear operations.