coordinate-system 2.4.2__tar.gz → 2.5.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- coordinate_system-2.5.1/MATHEMATICAL_FOUNDATION.md +800 -0
- {coordinate_system-2.4.2/coordinate_system.egg-info → coordinate_system-2.5.1}/PKG-INFO +3 -3
- {coordinate_system-2.4.2 → coordinate_system-2.5.1}/coordinate_system/__init__.py +48 -24
- {coordinate_system-2.4.2 → coordinate_system-2.5.1}/coordinate_system/curvature.py +38 -14
- coordinate_system-2.5.1/coordinate_system/differential_geometry.py +525 -0
- coordinate_system-2.5.1/coordinate_system/intrinsic_gradient_curvature.py +533 -0
- {coordinate_system-2.4.2 → coordinate_system-2.5.1/coordinate_system.egg-info}/PKG-INFO +3 -3
- {coordinate_system-2.4.2 → coordinate_system-2.5.1}/coordinate_system.egg-info/SOURCES.txt +1 -1
- {coordinate_system-2.4.2 → coordinate_system-2.5.1}/setup.py +4 -4
- coordinate_system-2.4.2/MATHEMATICAL_FOUNDATION.md +0 -1346
- coordinate_system-2.4.2/coordinate_system/differential_geometry.py +0 -814
- coordinate_system-2.4.2/coordinate_system/two_stage_curvature.py +0 -283
- {coordinate_system-2.4.2 → coordinate_system-2.5.1}/LICENSE +0 -0
- {coordinate_system-2.4.2 → coordinate_system-2.5.1}/MANIFEST.in +0 -0
- {coordinate_system-2.4.2 → coordinate_system-2.5.1}/README.md +0 -0
- {coordinate_system-2.4.2 → coordinate_system-2.5.1}/coordinate_system.egg-info/dependency_links.txt +0 -0
- {coordinate_system-2.4.2 → coordinate_system-2.5.1}/coordinate_system.egg-info/not-zip-safe +0 -0
- {coordinate_system-2.4.2 → coordinate_system-2.5.1}/coordinate_system.egg-info/top_level.txt +0 -0
- {coordinate_system-2.4.2 → coordinate_system-2.5.1}/coordinate_system_binding.cpp +0 -0
- {coordinate_system-2.4.2 → coordinate_system-2.5.1}/pmsys_minimal.hpp +0 -0
- {coordinate_system-2.4.2 → coordinate_system-2.5.1}/setup.cfg +0 -0
|
@@ -0,0 +1,800 @@
|
|
|
1
|
+
# Mathematical Foundation of Coordinate Systems
|
|
2
|
+
|
|
3
|
+
**A Unified Framework for 3D Geometry and Differential Geometry**
|
|
4
|
+
|
|
5
|
+
Author: PanGuoJun (romeosoft)
|
|
6
|
+
Version: 3.0.0 (Updated 2025-10-30)
|
|
7
|
+
License: MIT
|
|
8
|
+
|
|
9
|
+
**Revolutionary Updates in v3.0.0:**
|
|
10
|
+
- 🎯 **Unified Framework** - Single mathematical foundation for both 3D graphics and differential geometry
|
|
11
|
+
- 🚀 **Intrinsic Gradient Operator** - Core operator `G_μ = (c(u+h) - c(u))/h` for all geometric computations
|
|
12
|
+
- 📐 **Dual Frame System** - Clear separation of intrinsic (c) and embedding (C) frames
|
|
13
|
+
- 🧮 **Direct Curvature Computation** - No more Christoffel symbols - curvature from frame operators
|
|
14
|
+
- ⚡ **Computational Efficiency** - O(n³) vs traditional O(n⁶) complexity
|
|
15
|
+
- 🎨 **Practical Implementation** - Production-ready code with mathematical rigor
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Table of Contents
|
|
20
|
+
|
|
21
|
+
1. [Introduction](#1-introduction)
|
|
22
|
+
2. [Core Mathematical Framework](#2-core-mathematical-framework)
|
|
23
|
+
3. [Vectors and Basic Operations](#3-vectors-and-basic-operations)
|
|
24
|
+
4. [Coordinate Systems](#4-coordinate-systems)
|
|
25
|
+
5. [Dual Frame Theory](#5-dual-frame-theory)
|
|
26
|
+
6. [Intrinsic Gradient Operator](#6-intrinsic-gradient-operator)
|
|
27
|
+
7. [Curvature Computation](#7-curvature-computation)
|
|
28
|
+
8. [Quaternions and Rotations](#8-quaternions-and-rotations)
|
|
29
|
+
9. [Practical Applications](#9-practical-applications)
|
|
30
|
+
10. [Advanced Topics](#10-advanced-topics)
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 1. Introduction
|
|
35
|
+
|
|
36
|
+
### 1.1 The Unified Vision
|
|
37
|
+
|
|
38
|
+
Traditional approaches separate 3D coordinate systems from differential geometry. Our framework unifies them through the **Intrinsic Gradient Operator**, providing:
|
|
39
|
+
|
|
40
|
+
- **Single mathematical language** for both discrete and continuous geometry
|
|
41
|
+
- **Computational efficiency** through frame field operators
|
|
42
|
+
- **Geometric intuition** via direct frame manipulation
|
|
43
|
+
- **Practical implementation** with production-ready code
|
|
44
|
+
|
|
45
|
+
### 1.2 Fundamental Principles
|
|
46
|
+
|
|
47
|
+
**Principle 1:** All geometric information is encoded in coordinate frames
|
|
48
|
+
```
|
|
49
|
+
Geometry = {Frame Fields}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Principle 2:** Curvature emerges from frame field incompatibility
|
|
53
|
+
```
|
|
54
|
+
Curvature = [G_u, G_v] - G_{[u,v]}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Principle 3:** Computation follows geometric intuition
|
|
58
|
+
```
|
|
59
|
+
Compute what you see, not what you derive
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 2. Core Mathematical Framework
|
|
65
|
+
|
|
66
|
+
### 2.1 The Fundamental Equation
|
|
67
|
+
|
|
68
|
+
The core of our framework is the coordinate transformation equation:
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
P_world = P_local * CoordinateFrame
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Expanded for differential geometry:
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
Geometry = IntrinsicFrame * EmbeddingFrame⁻¹
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 2.2 Three Types of Gradients
|
|
81
|
+
|
|
82
|
+
| Gradient Type | Definition | Purpose |
|
|
83
|
+
|---------------|------------|---------|
|
|
84
|
+
| **World Gradient** | `∇ₓf = ∂f/∂x` | Global changes |
|
|
85
|
+
| **Embedding Gradient** | `∇ₑf = P(∇ₓf)` | Surface-relative changes |
|
|
86
|
+
| **Intrinsic Gradient** | `∇ᵢf = C⁻¹ ∘ ∇ₑf ∘ C` | Pure geometric changes |
|
|
87
|
+
|
|
88
|
+
### 2.3 Mathematical Notation
|
|
89
|
+
|
|
90
|
+
| Symbol | Meaning | Domain |
|
|
91
|
+
|--------|---------|--------|
|
|
92
|
+
| `c(u)` | Intrinsic frame | Pure geometry |
|
|
93
|
+
| `C(u)` | Embedding frame | Spatial embedding |
|
|
94
|
+
| `G_μ` | Intrinsic gradient operator | Connection |
|
|
95
|
+
| `[ , ]` | Lie bracket | Curvature measure |
|
|
96
|
+
| `R_uv` | Curvature tensor | Holonomy defect |
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## 3. Vectors and Basic Operations
|
|
101
|
+
|
|
102
|
+
### 3.1 Vector Definition
|
|
103
|
+
|
|
104
|
+
A vector represents direction and magnitude:
|
|
105
|
+
```
|
|
106
|
+
v = (x, y, z) ∈ ℝ³
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 3.2 Essential Operations
|
|
110
|
+
|
|
111
|
+
#### Dot Product (Metric)
|
|
112
|
+
```python
|
|
113
|
+
v1 · v2 = x₁x₂ + y₁y₂ + z₁z₂ = |v₁||v₂|cosθ
|
|
114
|
+
```
|
|
115
|
+
**Geometric meaning:** Measures alignment and projection.
|
|
116
|
+
|
|
117
|
+
#### Cross Product (Area)
|
|
118
|
+
```python
|
|
119
|
+
v1 × v2 = (y₁z₂ - z₁y₂, z₁x₂ - x₁z₂, x₁y₂ - y₁x₂)
|
|
120
|
+
```
|
|
121
|
+
**Geometric meaning:** Generates orthogonal vector, measures oriented area.
|
|
122
|
+
|
|
123
|
+
#### Triple Product (Volume)
|
|
124
|
+
```python
|
|
125
|
+
v1 · (v2 × v3) = det[v1, v2, v3]
|
|
126
|
+
```
|
|
127
|
+
**Geometric meaning:** Signed volume of parallelepiped.
|
|
128
|
+
|
|
129
|
+
### 3.3 Practical Implementation
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
class GeometricVector:
|
|
133
|
+
def __init__(self, x, y, z):
|
|
134
|
+
self.x, self.y, self.z = x, y, z
|
|
135
|
+
|
|
136
|
+
def dot(self, other):
|
|
137
|
+
return self.x*other.x + self.y*other.y + self.z*other.z
|
|
138
|
+
|
|
139
|
+
def cross(self, other):
|
|
140
|
+
return GeometricVector(
|
|
141
|
+
self.y*other.z - self.z*other.y,
|
|
142
|
+
self.z*other.x - self.x*other.z,
|
|
143
|
+
self.x*other.y - self.y*other.x
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
def norm(self):
|
|
147
|
+
return math.sqrt(self.dot(self))
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## 4. Coordinate Systems
|
|
153
|
+
|
|
154
|
+
### 4.1 Coordinate System Definition
|
|
155
|
+
|
|
156
|
+
A coordinate system is a movable reference frame:
|
|
157
|
+
```
|
|
158
|
+
Coord = {origin, basis, scale} = {o, {ux, uy, uz}, s}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### 4.2 Key Properties
|
|
162
|
+
|
|
163
|
+
**Orthonormality:**
|
|
164
|
+
```
|
|
165
|
+
ux · uy = uy · uz = uz · ux = 0
|
|
166
|
+
|ux| = |uy| = |uz| = 1
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Right-handedness:**
|
|
170
|
+
```
|
|
171
|
+
ux × uy = uz
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### 4.3 Transformation Operations
|
|
175
|
+
|
|
176
|
+
#### Point Transformation
|
|
177
|
+
```python
|
|
178
|
+
def transform_point(local_point, coord):
|
|
179
|
+
"""Transform point from local to world coordinates"""
|
|
180
|
+
return (coord.ux * local_point.x * coord.s.x +
|
|
181
|
+
coord.uy * local_point.y * coord.s.y +
|
|
182
|
+
coord.uz * local_point.z * coord.s.z +
|
|
183
|
+
coord.o)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
#### Inverse Transformation
|
|
187
|
+
```python
|
|
188
|
+
def inverse_transform(world_point, coord):
|
|
189
|
+
"""Transform point from world to local coordinates"""
|
|
190
|
+
relative = world_point - coord.o
|
|
191
|
+
return vec3(
|
|
192
|
+
relative.dot(coord.ux) / coord.s.x,
|
|
193
|
+
relative.dot(coord.uy) / coord.s.y,
|
|
194
|
+
relative.dot(coord.uz) / coord.s.z
|
|
195
|
+
)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
#### Composition
|
|
199
|
+
```python
|
|
200
|
+
def compose_coords(coord1, coord2):
|
|
201
|
+
"""Apply coord2 then coord1: result = coord1 * coord2"""
|
|
202
|
+
# Transform coord2's basis by coord1
|
|
203
|
+
new_ux = transform_point(coord2.ux * coord2.s.x, coord1)
|
|
204
|
+
new_uy = transform_point(coord2.uy * coord2.s.y, coord1)
|
|
205
|
+
new_uz = transform_point(coord2.uz * coord2.s.z, coord1)
|
|
206
|
+
new_o = transform_point(coord2.o, coord1)
|
|
207
|
+
|
|
208
|
+
return coord3(new_o, new_ux.normcopy(), new_uy.normcopy(), new_uz.normcopy())
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## 5. Dual Frame Theory
|
|
214
|
+
|
|
215
|
+
### 5.1 The Dual Frame Concept
|
|
216
|
+
|
|
217
|
+
Every point on a surface has two natural frames:
|
|
218
|
+
|
|
219
|
+
#### Intrinsic Frame `c(u)`
|
|
220
|
+
- **Purpose:** Pure geometric information
|
|
221
|
+
- **Properties:** Fully normalized, orthonormal
|
|
222
|
+
- **Construction:** Gram-Schmidt on tangent vectors
|
|
223
|
+
- **Scale:** Always `(1,1,1)`
|
|
224
|
+
|
|
225
|
+
#### Embedding Frame `C(u)`
|
|
226
|
+
- **Purpose:** Spatial embedding information
|
|
227
|
+
- **Properties:** Preserves metric tensor
|
|
228
|
+
- **Construction:** Orthogonalized but keeps lengths
|
|
229
|
+
- **Scale:** `(|r_u|, |r_v|, 1)`
|
|
230
|
+
|
|
231
|
+
### 5.2 Frame Construction
|
|
232
|
+
|
|
233
|
+
```python
|
|
234
|
+
def construct_intrinsic_frame(r_u, r_v):
|
|
235
|
+
"""Construct intrinsic frame c(u)"""
|
|
236
|
+
# Normalize and orthogonalize
|
|
237
|
+
e1 = r_u.normcopy()
|
|
238
|
+
e2_orth = r_v - e1 * r_v.dot(e1)
|
|
239
|
+
e2 = e2_orth.normcopy()
|
|
240
|
+
e3 = e1.cross(e2).normcopy()
|
|
241
|
+
|
|
242
|
+
# Use 3-parameter constructor for normalized frame
|
|
243
|
+
return coord3(e1, e2, e3)
|
|
244
|
+
|
|
245
|
+
def construct_embedding_frame(r_u, r_v, position):
|
|
246
|
+
"""Construct embedding frame C(u) with metric information"""
|
|
247
|
+
# Preserve lengths through orthogonalization
|
|
248
|
+
e1 = r_u.normcopy()
|
|
249
|
+
e1_length = r_u.norm()
|
|
250
|
+
|
|
251
|
+
e2_orth = r_v - e1 * r_v.dot(e1)
|
|
252
|
+
e2 = e2_orth.normcopy()
|
|
253
|
+
e2_length = e2_orth.norm()
|
|
254
|
+
|
|
255
|
+
e3 = e1.cross(e2).normcopy()
|
|
256
|
+
|
|
257
|
+
# Use 5-parameter constructor with scale
|
|
258
|
+
scale = vec3(e1_length, e2_length, 1.0)
|
|
259
|
+
return coord3(position, scale, e1, e2, e3)
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### 5.3 Metric Extraction
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
def extract_metric(embedding_frame):
|
|
266
|
+
"""Extract metric tensor from embedding frame"""
|
|
267
|
+
VX = embedding_frame.VX() # ux * s.x
|
|
268
|
+
VY = embedding_frame.VY() # uy * s.y
|
|
269
|
+
|
|
270
|
+
E = VX.dot(VX) # g_uu
|
|
271
|
+
F = VX.dot(VY) # g_uv
|
|
272
|
+
G = VY.dot(VY) # g_vv
|
|
273
|
+
|
|
274
|
+
return MetricTensor(E, F, G)
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## 6. Intrinsic Gradient Operator
|
|
280
|
+
|
|
281
|
+
### 6.1 Core Definition
|
|
282
|
+
|
|
283
|
+
The **Intrinsic Gradient Operator** measures how frames change along the surface:
|
|
284
|
+
|
|
285
|
+
```
|
|
286
|
+
G_μ = (c(u + h_μ) - c(u)) / h_μ
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
More precisely:
|
|
290
|
+
```
|
|
291
|
+
G_μ = [c(u+h_μ) · c(u)⁻¹] / C(u+h_μ) - I / C(u)
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### 6.2 Mathematical Properties
|
|
295
|
+
|
|
296
|
+
**Geometric Interpretation:**
|
|
297
|
+
- `G_μ` measures frame field derivative
|
|
298
|
+
- Contains connection coefficients
|
|
299
|
+
- Encodes parallel transport information
|
|
300
|
+
|
|
301
|
+
**Transformation Properties:**
|
|
302
|
+
- Tensor under coordinate changes
|
|
303
|
+
- Lie algebra valued
|
|
304
|
+
- Measures path dependence
|
|
305
|
+
|
|
306
|
+
### 6.3 Implementation
|
|
307
|
+
|
|
308
|
+
```python
|
|
309
|
+
class IntrinsicGradientOperator:
|
|
310
|
+
def __init__(self, surface, step_size=1e-4):
|
|
311
|
+
self.surface = surface
|
|
312
|
+
self.h = step_size
|
|
313
|
+
|
|
314
|
+
def compute(self, u, v, direction):
|
|
315
|
+
"""Compute G_μ operator"""
|
|
316
|
+
# Current frames
|
|
317
|
+
c_center = self.compute_intrinsic_frame(u, v)
|
|
318
|
+
C_center = self.compute_embedding_frame(u, v)
|
|
319
|
+
|
|
320
|
+
# Shifted frames
|
|
321
|
+
if direction == 'u':
|
|
322
|
+
c_shifted = self.compute_intrinsic_frame(u + self.h, v)
|
|
323
|
+
C_shifted = self.compute_embedding_frame(u + self.h, v)
|
|
324
|
+
else: # 'v'
|
|
325
|
+
c_shifted = self.compute_intrinsic_frame(u, v + self.h)
|
|
326
|
+
C_shifted = self.compute_embedding_frame(u, v + self.h)
|
|
327
|
+
|
|
328
|
+
# Core formula: G = (c2/c1)/C2 - I/C1
|
|
329
|
+
G_prime = (c_shifted / c_center) / C_shifted - ONEC / C_center
|
|
330
|
+
|
|
331
|
+
# Finite difference scaling
|
|
332
|
+
if abs(self.h) > 1e-14:
|
|
333
|
+
G_raw = _coord3_scalar_mul(G_prime, 1.0/self.h)
|
|
334
|
+
else:
|
|
335
|
+
G_raw = G_prime
|
|
336
|
+
|
|
337
|
+
# Metric correction
|
|
338
|
+
metric = MetricTensor.from_coord3(C_center)
|
|
339
|
+
correction = metric.correction_factor()
|
|
340
|
+
G_corrected = _coord3_scalar_mul(G_raw, correction)
|
|
341
|
+
|
|
342
|
+
return G_corrected
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### 6.4 Operator Components
|
|
346
|
+
|
|
347
|
+
The intrinsic gradient operator contains:
|
|
348
|
+
|
|
349
|
+
```
|
|
350
|
+
G_μ = [
|
|
351
|
+
[Γ¹₁μ Γ¹₂μ ω₁μ], # Connection coefficients
|
|
352
|
+
[Γ²₁μ Γ²₂μ ω₂μ], # and normal components
|
|
353
|
+
[L_μ M_μ 0 ] # Extrinsic curvature
|
|
354
|
+
]
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
Where:
|
|
358
|
+
- `Γᵏᵢⱼ`: Christoffel symbols (intrinsic connection)
|
|
359
|
+
- `ωᵢ`: Connection 1-form components
|
|
360
|
+
- `L_μ, M_μ`: Second fundamental form derivatives
|
|
361
|
+
|
|
362
|
+
---
|
|
363
|
+
|
|
364
|
+
## 7. Curvature Computation
|
|
365
|
+
|
|
366
|
+
### 7.1 Curvature from Operators
|
|
367
|
+
|
|
368
|
+
Curvature emerges from the non-commutativity of intrinsic gradients:
|
|
369
|
+
|
|
370
|
+
```
|
|
371
|
+
R_uv = [G_u, G_v] - G_{[u,v]}
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
Where:
|
|
375
|
+
- `[G_u, G_v] = G_u ∘ G_v - G_v ∘ G_u` (Lie bracket)
|
|
376
|
+
- `G_{[u,v]}` (Lie derivative term)
|
|
377
|
+
|
|
378
|
+
### 7.2 Gaussian Curvature Extraction
|
|
379
|
+
|
|
380
|
+
```python
|
|
381
|
+
def compute_gaussian_curvature(G_u, G_v, metric):
|
|
382
|
+
"""Extract Gaussian curvature from operators"""
|
|
383
|
+
# Compute curvature tensor
|
|
384
|
+
R_uv = compute_curvature_tensor(G_u, G_v)
|
|
385
|
+
|
|
386
|
+
# Extract antisymmetric part (intrinsic curvature)
|
|
387
|
+
R_01 = R_uv.ux.y # R^1_{212} component
|
|
388
|
+
R_10 = R_uv.uy.x # R^2_{112} component
|
|
389
|
+
R_12_antisym = (R_01 - R_10) / 2.0
|
|
390
|
+
|
|
391
|
+
# Gaussian curvature
|
|
392
|
+
if abs(metric.det) > 1e-10:
|
|
393
|
+
K = R_12_antisym / metric.det
|
|
394
|
+
else:
|
|
395
|
+
K = 0.0
|
|
396
|
+
|
|
397
|
+
return K
|
|
398
|
+
|
|
399
|
+
def compute_curvature_tensor(G_u, G_v, include_lie_derivative=True):
|
|
400
|
+
"""Compute full curvature tensor"""
|
|
401
|
+
# Lie bracket term
|
|
402
|
+
commutator = G_u * G_v - G_v * G_u
|
|
403
|
+
|
|
404
|
+
if not include_lie_derivative:
|
|
405
|
+
return commutator
|
|
406
|
+
|
|
407
|
+
# Lie derivative term (for non-coordinate bases)
|
|
408
|
+
# G_{[u,v]} = ∂G_v/∂u - ∂G_u/∂v
|
|
409
|
+
lie_derivative = compute_lie_derivative(G_u, G_v)
|
|
410
|
+
|
|
411
|
+
return commutator - lie_derivative
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
### 7.3 Complete Curvature Pipeline
|
|
415
|
+
|
|
416
|
+
```python
|
|
417
|
+
class SurfaceCurvature:
|
|
418
|
+
def __init__(self, surface, step_size=1e-4):
|
|
419
|
+
self.surface = surface
|
|
420
|
+
self.grad_op = IntrinsicGradientOperator(surface, step_size)
|
|
421
|
+
|
|
422
|
+
def compute_at_point(self, u, v):
|
|
423
|
+
"""Complete curvature analysis at point (u,v)"""
|
|
424
|
+
# Compute operators
|
|
425
|
+
G_u = self.grad_op.compute(u, v, 'u')
|
|
426
|
+
G_v = self.grad_op.compute(u, v, 'v')
|
|
427
|
+
|
|
428
|
+
# Compute metric
|
|
429
|
+
C = self.grad_op.compute_embedding_frame(u, v)
|
|
430
|
+
metric = MetricTensor.from_coord3(C)
|
|
431
|
+
|
|
432
|
+
# Compute curvatures
|
|
433
|
+
K_gaussian = compute_gaussian_curvature(G_u, G_v, metric)
|
|
434
|
+
|
|
435
|
+
# Second fundamental form approach
|
|
436
|
+
L, M, N = self.compute_second_fundamental_form(u, v)
|
|
437
|
+
K_second_form = (L*N - M*M) / metric.det if metric.det > 1e-10 else 0.0
|
|
438
|
+
|
|
439
|
+
# Mean curvature
|
|
440
|
+
H = (metric.G*L - 2*metric.F*M + metric.E*N) / (2*metric.det)
|
|
441
|
+
|
|
442
|
+
return {
|
|
443
|
+
'gaussian_curvature': K_gaussian,
|
|
444
|
+
'gaussian_curvature_second_form': K_second_form,
|
|
445
|
+
'mean_curvature': H,
|
|
446
|
+
'metric': metric,
|
|
447
|
+
'operators': (G_u, G_v)
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
def compute_second_fundamental_form(self, u, v):
|
|
451
|
+
"""Compute via intrinsic gradient operators"""
|
|
452
|
+
G_u, G_v = self.grad_op.compute_both(u, v)
|
|
453
|
+
r_u = self.surface.tangent_u(u, v)
|
|
454
|
+
r_v = self.surface.tangent_v(u, v)
|
|
455
|
+
|
|
456
|
+
# Normal derivatives from operators
|
|
457
|
+
dn_du = vec3(G_u.uz.x, G_u.uz.y, G_u.uz.z)
|
|
458
|
+
dn_dv = vec3(G_v.uz.x, G_v.uz.y, G_v.uz.z)
|
|
459
|
+
|
|
460
|
+
L = -dn_du.dot(r_u)
|
|
461
|
+
M = -(dn_du.dot(r_v) + dn_dv.dot(r_u)) / 2.0
|
|
462
|
+
N = -dn_dv.dot(r_v)
|
|
463
|
+
|
|
464
|
+
return L, M, N
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
---
|
|
468
|
+
|
|
469
|
+
## 8. Quaternions and Rotations
|
|
470
|
+
|
|
471
|
+
### 8.1 Quaternion Fundamentals
|
|
472
|
+
|
|
473
|
+
Quaternions provide efficient rotation representation:
|
|
474
|
+
```
|
|
475
|
+
q = w + xi + yj + zk = (w, x, y, z)
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
**Key properties:**
|
|
479
|
+
- `i² = j² = k² = ijk = -1`
|
|
480
|
+
- Compact (4 values vs 9 for matrices)
|
|
481
|
+
- Natural interpolation (SLERP)
|
|
482
|
+
- No gimbal lock
|
|
483
|
+
|
|
484
|
+
### 8.2 Rotation Operations
|
|
485
|
+
|
|
486
|
+
#### From Angle-Axis
|
|
487
|
+
```python
|
|
488
|
+
def quat_from_angle_axis(angle, axis):
|
|
489
|
+
"""Create quaternion from rotation"""
|
|
490
|
+
axis_norm = axis.normcopy()
|
|
491
|
+
half_angle = angle * 0.5
|
|
492
|
+
w = math.cos(half_angle)
|
|
493
|
+
xyz = axis_norm * math.sin(half_angle)
|
|
494
|
+
return quat(w, xyz.x, xyz.y, xyz.z)
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
#### Vector Rotation
|
|
498
|
+
```python
|
|
499
|
+
def rotate_vector(v, q):
|
|
500
|
+
"""Rotate vector by quaternion"""
|
|
501
|
+
# Convert vector to pure quaternion
|
|
502
|
+
v_quat = quat(0, v.x, v.y, v.z)
|
|
503
|
+
# Rotate: v' = q * v * q⁻¹
|
|
504
|
+
result = q * v_quat * q.conjugate()
|
|
505
|
+
return vec3(result.x, result.y, result.z)
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
### 8.3 Frame Rotation
|
|
509
|
+
|
|
510
|
+
```python
|
|
511
|
+
def rotate_frame(frame, rotation_quat):
|
|
512
|
+
"""Rotate coordinate frame by quaternion"""
|
|
513
|
+
new_ux = rotate_vector(frame.ux, rotation_quat)
|
|
514
|
+
new_uy = rotate_vector(frame.uy, rotation_quat)
|
|
515
|
+
new_uz = rotate_vector(frame.uz, rotation_quat)
|
|
516
|
+
|
|
517
|
+
return coord3(frame.o, new_ux, new_uy, new_uz)
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
---
|
|
521
|
+
|
|
522
|
+
## 9. Practical Applications
|
|
523
|
+
|
|
524
|
+
### 9.1 3D Graphics and Animation
|
|
525
|
+
|
|
526
|
+
#### Hierarchical Transformations
|
|
527
|
+
```python
|
|
528
|
+
class SceneNode:
|
|
529
|
+
def __init__(self, local_frame):
|
|
530
|
+
self.local_frame = local_frame
|
|
531
|
+
self.world_frame = local_frame.copy()
|
|
532
|
+
self.children = []
|
|
533
|
+
|
|
534
|
+
def update_transform(self, parent_frame=None):
|
|
535
|
+
"""Update world transformation"""
|
|
536
|
+
if parent_frame:
|
|
537
|
+
self.world_frame = self.local_frame * parent_frame
|
|
538
|
+
else:
|
|
539
|
+
self.world_frame = self.local_frame.copy()
|
|
540
|
+
|
|
541
|
+
for child in self.children:
|
|
542
|
+
child.update_transform(self.world_frame)
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
#### Camera System
|
|
546
|
+
```python
|
|
547
|
+
class Camera:
|
|
548
|
+
def __init__(self, position, target, up=vec3(0,1,0)):
|
|
549
|
+
self.frame = create_look_at_frame(position, target, up)
|
|
550
|
+
|
|
551
|
+
def get_view_matrix(self):
|
|
552
|
+
"""Get view matrix (world to camera)"""
|
|
553
|
+
return self.frame.inverse().to_matrix()
|
|
554
|
+
|
|
555
|
+
def project_point(self, world_point):
|
|
556
|
+
"""Project world point to camera space"""
|
|
557
|
+
return world_point / self.frame
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
### 9.2 Physics and Robotics
|
|
561
|
+
|
|
562
|
+
#### Rigid Body Dynamics
|
|
563
|
+
```python
|
|
564
|
+
class RigidBody:
|
|
565
|
+
def __init__(self, mass, inertia):
|
|
566
|
+
self.mass = mass
|
|
567
|
+
self.inertia = inertia
|
|
568
|
+
self.frame = coord3() # Position and orientation
|
|
569
|
+
self.velocity = vec3(0,0,0)
|
|
570
|
+
self.angular_velocity = vec3(0,0,0)
|
|
571
|
+
|
|
572
|
+
def apply_force(self, force, point):
|
|
573
|
+
"""Apply force at specific point"""
|
|
574
|
+
# Linear acceleration
|
|
575
|
+
linear_accel = force * (1.0 / self.mass)
|
|
576
|
+
|
|
577
|
+
# Torque and angular acceleration
|
|
578
|
+
r = point - self.frame.o
|
|
579
|
+
torque = r.cross(force)
|
|
580
|
+
angular_accel = torque * (1.0 / self.inertia)
|
|
581
|
+
|
|
582
|
+
return linear_accel, angular_accel
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
### 9.3 Differential Geometry Applications
|
|
586
|
+
|
|
587
|
+
#### Surface Analysis
|
|
588
|
+
```python
|
|
589
|
+
def analyze_surface_curvature(surface, resolution=100):
|
|
590
|
+
"""Compute curvature map over surface"""
|
|
591
|
+
u_range = surface.u_domain
|
|
592
|
+
v_range = surface.v_domain
|
|
593
|
+
|
|
594
|
+
curvature_calculator = IntrinsicGradientCurvatureCalculator(surface)
|
|
595
|
+
|
|
596
|
+
curvature_map = np.zeros((resolution, resolution))
|
|
597
|
+
|
|
598
|
+
for i, u in enumerate(np.linspace(u_range[0], u_range[1], resolution)):
|
|
599
|
+
for j, v in enumerate(np.linspace(v_range[0], v_range[1], resolution)):
|
|
600
|
+
result = curvature_calculator.compute_all_curvatures(u, v)
|
|
601
|
+
curvature_map[i, j] = result['gaussian_curvature']
|
|
602
|
+
|
|
603
|
+
return curvature_map
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
#### Geodesic Tracing
|
|
607
|
+
```python
|
|
608
|
+
def trace_geodesic(surface, start_point, initial_direction, steps=100, step_size=0.01):
|
|
609
|
+
"""Trace geodesic using parallel transport"""
|
|
610
|
+
path = [start_point]
|
|
611
|
+
current_point = start_point
|
|
612
|
+
current_direction = initial_direction.normcopy()
|
|
613
|
+
|
|
614
|
+
for step in range(steps):
|
|
615
|
+
# Compute frames
|
|
616
|
+
frame = surface.get_frame(current_point)
|
|
617
|
+
|
|
618
|
+
# Parallel transport direction
|
|
619
|
+
current_direction = parallel_transport(current_direction, frame)
|
|
620
|
+
|
|
621
|
+
# Step along geodesic
|
|
622
|
+
next_point = current_point + current_direction * step_size
|
|
623
|
+
path.append(next_point)
|
|
624
|
+
current_point = next_point
|
|
625
|
+
|
|
626
|
+
return path
|
|
627
|
+
```
|
|
628
|
+
|
|
629
|
+
---
|
|
630
|
+
|
|
631
|
+
## 10. Advanced Topics
|
|
632
|
+
|
|
633
|
+
### 10.1 Connection to General Relativity
|
|
634
|
+
|
|
635
|
+
Our framework naturally extends to GR through the tetrad formalism:
|
|
636
|
+
|
|
637
|
+
```python
|
|
638
|
+
def schwarzschild_tetrad(r, theta, phi, M):
|
|
639
|
+
"""Tetrad for Schwarzschild metric"""
|
|
640
|
+
r_s = 2 * M
|
|
641
|
+
alpha = math.sqrt(1 - r_s / r)
|
|
642
|
+
|
|
643
|
+
# Orthonormal basis
|
|
644
|
+
e_t = vec3(1/alpha, 0, 0) # Timelike
|
|
645
|
+
e_r = vec3(0, alpha, 0) # Radial
|
|
646
|
+
e_theta = vec3(0, 0, r) # Angular
|
|
647
|
+
e_phi = vec3(0, 0, r*math.sin(theta))
|
|
648
|
+
|
|
649
|
+
return coord4(e_t, e_r, e_theta, e_phi)
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
### 10.2 Computational Complexity
|
|
653
|
+
|
|
654
|
+
**Traditional vs Our Method:**
|
|
655
|
+
|
|
656
|
+
| Operation | Traditional | Frame Field | Speedup |
|
|
657
|
+
|-----------|-------------|-------------|---------|
|
|
658
|
+
| Metric | O(n²) | O(n²) | 1× |
|
|
659
|
+
| Connection | O(n⁴) | O(n³) | n× |
|
|
660
|
+
| Curvature | O(n⁶) | O(n³) | n³× |
|
|
661
|
+
| Geodesics | O(n⁴) | O(n²) | n²× |
|
|
662
|
+
|
|
663
|
+
For n=3 (3D surfaces): **~27× theoretical speedup**
|
|
664
|
+
|
|
665
|
+
### 10.3 Numerical Validation
|
|
666
|
+
|
|
667
|
+
```python
|
|
668
|
+
def validate_sphere_curvature(radius=1.0, points=24):
|
|
669
|
+
"""Validate curvature computation on sphere"""
|
|
670
|
+
sphere = Sphere(radius)
|
|
671
|
+
calculator = IntrinsicGradientCurvatureCalculator(sphere)
|
|
672
|
+
|
|
673
|
+
theoretical_K = 1.0 / (radius * radius)
|
|
674
|
+
errors = []
|
|
675
|
+
|
|
676
|
+
for i in range(points):
|
|
677
|
+
u = math.pi * (i + 0.5) / points # Avoid poles
|
|
678
|
+
v = 2 * math.pi * i / points
|
|
679
|
+
|
|
680
|
+
result = calculator.compute_all_curvatures(u, v)
|
|
681
|
+
computed_K = result['gaussian_curvature_tensor']
|
|
682
|
+
|
|
683
|
+
error = abs(computed_K - theoretical_K) / theoretical_K
|
|
684
|
+
errors.append(error)
|
|
685
|
+
|
|
686
|
+
avg_error = sum(errors) / len(errors)
|
|
687
|
+
max_error = max(errors)
|
|
688
|
+
|
|
689
|
+
print(f"Average error: {avg_error*100:.6f}%")
|
|
690
|
+
print(f"Maximum error: {max_error*100:.6f}%")
|
|
691
|
+
print(f"Theoretical K: {theoretical_K:.6f}")
|
|
692
|
+
|
|
693
|
+
return avg_error, max_error
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
### 10.4 Extension to Higher Dimensions
|
|
697
|
+
|
|
698
|
+
```python
|
|
699
|
+
class CoordN:
|
|
700
|
+
"""N-dimensional coordinate system"""
|
|
701
|
+
def __init__(self, n):
|
|
702
|
+
self.dimension = n
|
|
703
|
+
self.basis = [vec_n(n) for _ in range(n)]
|
|
704
|
+
self.origin = vec_n(n)
|
|
705
|
+
self.scale = vec_n(n, fill=1.0)
|
|
706
|
+
|
|
707
|
+
def transform_point(self, point):
|
|
708
|
+
"""Transform point to this coordinate system"""
|
|
709
|
+
result = self.origin.copy()
|
|
710
|
+
for i in range(self.dimension):
|
|
711
|
+
result += self.basis[i] * point[i] * self.scale[i]
|
|
712
|
+
return result
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
---
|
|
716
|
+
|
|
717
|
+
## Implementation Guidelines
|
|
718
|
+
|
|
719
|
+
### Performance Optimization
|
|
720
|
+
|
|
721
|
+
1. **Use intrinsic gradient operators** instead of Christoffel symbols
|
|
722
|
+
2. **Cache frame computations** for repeated evaluations
|
|
723
|
+
3. **Vectorize operations** over mesh points
|
|
724
|
+
4. **Use quaternions** for rotation composition
|
|
725
|
+
|
|
726
|
+
### Numerical Stability
|
|
727
|
+
|
|
728
|
+
1. **Optimal step size**: `h ≈ 1e-3` for O(h²) convergence
|
|
729
|
+
2. **Metric correction**: Always apply `1/√det(g)` normalization
|
|
730
|
+
3. **Frame orthonormalization**: Regular Gram-Schmidt application
|
|
731
|
+
4. **Quaternion normalization**: Maintain unit quaternions
|
|
732
|
+
|
|
733
|
+
### Code Organization
|
|
734
|
+
|
|
735
|
+
```
|
|
736
|
+
coordinate_system/
|
|
737
|
+
├── core/
|
|
738
|
+
│ ├── vectors.py # Vector operations
|
|
739
|
+
│ ├── quaternions.py # Rotation representation
|
|
740
|
+
│ └── coord3.py # Coordinate system class
|
|
741
|
+
├── geometry/
|
|
742
|
+
│ ├── surfaces.py # Surface definitions
|
|
743
|
+
│ ├── metrics.py # Metric tensor
|
|
744
|
+
│ └── curvature.py # Curvature computation
|
|
745
|
+
└── applications/
|
|
746
|
+
├── graphics.py # 3D graphics
|
|
747
|
+
├── physics.py # Physics simulation
|
|
748
|
+
└── analysis.py # Geometric analysis
|
|
749
|
+
```
|
|
750
|
+
|
|
751
|
+
---
|
|
752
|
+
|
|
753
|
+
## Key Insights
|
|
754
|
+
|
|
755
|
+
1. **Geometry is local**: All geometric information is encoded in frame fields
|
|
756
|
+
2. **Curvature is algebraic**: No need for complicated tensor calculus
|
|
757
|
+
3. **Computation follows intuition**: Compute what you see geometrically
|
|
758
|
+
4. **Unified framework**: Same mathematics for graphics and differential geometry
|
|
759
|
+
5. **Practical efficiency**: Significant speedups over traditional methods
|
|
760
|
+
|
|
761
|
+
---
|
|
762
|
+
|
|
763
|
+
## References
|
|
764
|
+
|
|
765
|
+
**Core Theory:**
|
|
766
|
+
1. Cartan, É. (1926). "La géométrie des espaces de Riemann"
|
|
767
|
+
2. Kobayashi, S., & Nomizu, K. (1963). "Foundations of Differential Geometry"
|
|
768
|
+
3. Frankel, T. (2011). "The Geometry of Physics"
|
|
769
|
+
|
|
770
|
+
**Computational Methods:**
|
|
771
|
+
1. Meyer, M., et al. (2003). "Discrete Differential-Geometry Operators"
|
|
772
|
+
2. Crane, K., et al. (2013). "Trivial Connections on Discrete Surfaces"
|
|
773
|
+
3. Pan, G. (2025). "Frame Field Combination Operators" (Original research)
|
|
774
|
+
|
|
775
|
+
**Practical Implementation:**
|
|
776
|
+
1. GitHub: [Coordinate-System Library](https://github.com/panguojun/Coordinate-System)
|
|
777
|
+
2. Examples: [Differential Geometry Applications](../examples/)
|
|
778
|
+
3. Tests: [Validation and Verification](../tests/)
|
|
779
|
+
|
|
780
|
+
---
|
|
781
|
+
|
|
782
|
+
## Conclusion
|
|
783
|
+
|
|
784
|
+
This mathematical foundation provides:
|
|
785
|
+
|
|
786
|
+
- ✅ **Unified framework** for 3D graphics and differential geometry
|
|
787
|
+
- ✅ **Computational efficiency** through intrinsic gradient operators
|
|
788
|
+
- ✅ **Geometric intuition** via direct frame manipulation
|
|
789
|
+
- ✅ **Practical implementation** with production-ready code
|
|
790
|
+
- ✅ **Theoretical rigor** with connections to modern physics
|
|
791
|
+
|
|
792
|
+
The **Intrinsic Gradient Operator** `G_μ = (c(u+h) - c(u))/h` serves as the fundamental building block, enabling efficient computation of all geometric quantities while maintaining mathematical elegance and practical utility.
|
|
793
|
+
|
|
794
|
+
---
|
|
795
|
+
|
|
796
|
+
*"Geometry is not true, it is advantageous." - Henri Poincaré*
|
|
797
|
+
|
|
798
|
+
*Written by PanGuoJun (romeosoft)*
|
|
799
|
+
*License: MIT - Free to use and modify*
|
|
800
|
+
*Last Updated: 2025-10-30*
|