coordinate-system 2.5.4__tar.gz → 2.5.7__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.
Files changed (19) hide show
  1. {coordinate_system-2.5.4/coordinate_system.egg-info → coordinate_system-2.5.7}/PKG-INFO +1 -1
  2. {coordinate_system-2.5.4 → coordinate_system-2.5.7}/coordinate_system/__init__.py +12 -23
  3. coordinate_system-2.5.7/coordinate_system/curvature.py +321 -0
  4. {coordinate_system-2.5.4 → coordinate_system-2.5.7}/coordinate_system/differential_geometry.py +215 -199
  5. {coordinate_system-2.5.4 → coordinate_system-2.5.7/coordinate_system.egg-info}/PKG-INFO +1 -1
  6. {coordinate_system-2.5.4 → coordinate_system-2.5.7}/coordinate_system.egg-info/SOURCES.txt +0 -1
  7. {coordinate_system-2.5.4 → coordinate_system-2.5.7}/coordinate_system_binding.cpp +2 -37
  8. {coordinate_system-2.5.4 → coordinate_system-2.5.7}/pmsys_minimal.hpp +15 -25
  9. {coordinate_system-2.5.4 → coordinate_system-2.5.7}/setup.py +2 -2
  10. coordinate_system-2.5.4/coordinate_system/coord3_wrapper.py +0 -300
  11. coordinate_system-2.5.4/coordinate_system/curvature.py +0 -838
  12. {coordinate_system-2.5.4 → coordinate_system-2.5.7}/LICENSE +0 -0
  13. {coordinate_system-2.5.4 → coordinate_system-2.5.7}/MANIFEST.in +0 -0
  14. {coordinate_system-2.5.4 → coordinate_system-2.5.7}/MATHEMATICAL_FOUNDATION.md +0 -0
  15. {coordinate_system-2.5.4 → coordinate_system-2.5.7}/README.md +0 -0
  16. {coordinate_system-2.5.4 → coordinate_system-2.5.7}/coordinate_system.egg-info/dependency_links.txt +0 -0
  17. {coordinate_system-2.5.4 → coordinate_system-2.5.7}/coordinate_system.egg-info/not-zip-safe +0 -0
  18. {coordinate_system-2.5.4 → coordinate_system-2.5.7}/coordinate_system.egg-info/top_level.txt +0 -0
  19. {coordinate_system-2.5.4 → coordinate_system-2.5.7}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: coordinate_system
3
- Version: 2.5.4
3
+ Version: 2.5.7
4
4
  Summary: High-performance 3D coordinate system library with Intrinsic Gradient Operator method for curvature computation, achieving machine-precision accuracy
5
5
  Home-page: https://github.com/panguojun/Coordinate-System
6
6
  Author: PanGuoJun
@@ -4,7 +4,7 @@ from .coordinate_system import vec3, vec2
4
4
  from .coordinate_system import quat
5
5
  from .coordinate_system import coord3
6
6
 
7
- # Differential geometry module (v3.0.0+)
7
+ # Differential geometry module (v3.3.0+)
8
8
  from .differential_geometry import (
9
9
  # Classes
10
10
  Surface,
@@ -17,7 +17,7 @@ from .differential_geometry import (
17
17
  # Main functions
18
18
  compute_intrinsic_gradient,
19
19
  compute_gaussian_curvature,
20
- compute_curvature_tensor,
20
+ compute_mean_curvature,
21
21
  compute_all_curvatures,
22
22
  )
23
23
 
@@ -30,9 +30,11 @@ from .curvature import (
30
30
  principal_curvatures,
31
31
  all_curvatures,
32
32
 
33
- # Lie group method
34
- LieGroupCurvatureCalculator,
35
- gaussian_curvature_lie,
33
+ # Intrinsic Gradient Operator method
34
+ intrinsic_gradient_gaussian_curvature,
35
+ intrinsic_gradient_mean_curvature,
36
+ intrinsic_gradient_principal_curvatures,
37
+ intrinsic_gradient_all_curvatures,
36
38
  compare_methods,
37
39
 
38
40
  # Utility functions
@@ -41,15 +43,6 @@ from .curvature import (
41
43
  richardson_extrapolation,
42
44
  )
43
45
 
44
- # Intrinsic Gradient Operator method (v2.4.0+)
45
- # Now imported from curvature module for backward compatibility
46
- from .curvature import (
47
- intrinsic_gradient_gaussian_curvature,
48
- intrinsic_gradient_mean_curvature,
49
- intrinsic_gradient_principal_curvatures,
50
- intrinsic_gradient_all_curvatures,
51
- )
52
-
53
46
  __all__ = [
54
47
  # Constants
55
48
  'ZERO3','UNITX','UNITY','UNITZ','ONE3','ONE4','ONEC',
@@ -57,14 +50,14 @@ __all__ = [
57
50
  # Core types
58
51
  'vec3', 'vec2', 'quat', 'coord3', 'lerp',
59
52
 
60
- # Differential geometry classes (v3.0.0+)
53
+ # Differential geometry classes (v3.3.0+)
61
54
  'Surface', 'Sphere', 'Torus',
62
55
  'MetricTensor', 'IntrinsicGradientOperator', 'IntrinsicGradientCurvatureCalculator',
63
56
 
64
- # Differential geometry functions (v3.0.0+)
57
+ # Differential geometry functions (v3.3.0+)
65
58
  'compute_intrinsic_gradient',
66
59
  'compute_gaussian_curvature',
67
- 'compute_curvature_tensor',
60
+ 'compute_mean_curvature',
68
61
  'compute_all_curvatures',
69
62
 
70
63
  # High-precision curvature module - Classical method (v2.3.0+)
@@ -72,16 +65,12 @@ __all__ = [
72
65
  'gaussian_curvature', 'mean_curvature',
73
66
  'principal_curvatures', 'all_curvatures',
74
67
 
75
- # Lie group method (v2.3.0+)
76
- 'LieGroupCurvatureCalculator',
77
- 'gaussian_curvature_lie',
78
- 'compare_methods',
79
-
80
- # Intrinsic Gradient Operator method (v2.4.0+, merged into other modules)
68
+ # Intrinsic Gradient Operator method (v2.4.0+)
81
69
  'intrinsic_gradient_gaussian_curvature',
82
70
  'intrinsic_gradient_mean_curvature',
83
71
  'intrinsic_gradient_principal_curvatures',
84
72
  'intrinsic_gradient_all_curvatures',
73
+ 'compare_methods',
85
74
 
86
75
  # Utility functions
87
76
  'derivative_5pt', 'derivative_2nd_5pt', 'richardson_extrapolation',
@@ -0,0 +1,321 @@
1
+ """
2
+ High-Precision Discrete Curvature Computation Module
3
+ ====================================================
4
+
5
+ This module provides optimized discrete curvature computation methods
6
+ based on traditional differential geometry with high-order finite differences.
7
+
8
+ Author: PanGuoJun
9
+ Date: 2025-10-31
10
+ """
11
+
12
+ import numpy as np
13
+ from typing import Tuple, Optional, Dict, List, Callable, Union
14
+ from .differential_geometry import (
15
+ Surface, MetricTensor, IntrinsicGradientOperator, IntrinsicGradientCurvatureCalculator,
16
+ compute_gaussian_curvature, compute_mean_curvature, compute_all_curvatures
17
+ )
18
+ from .coordinate_system import coord3, vec3
19
+
20
+
21
+ # ========== High-Order Finite Difference Operators ==========
22
+
23
+ def derivative_5pt(f: Callable[[float], np.ndarray], x: float, h: float) -> np.ndarray:
24
+ """
25
+ 5-point finite difference formula for first derivative
26
+ """
27
+ return (-f(x + 2*h) + 8*f(x + h) - 8*f(x - h) + f(x - 2*h)) / (12*h)
28
+
29
+
30
+ def derivative_2nd_5pt(f: Callable[[float], np.ndarray], x: float, h: float) -> np.ndarray:
31
+ """
32
+ 5-point finite difference formula for second derivative
33
+ """
34
+ return (-f(x + 2*h) + 16*f(x + h) - 30*f(x) + 16*f(x - h) - f(x - 2*h)) / (12*h*h)
35
+
36
+
37
+ def richardson_extrapolation(f_h: float, f_2h: float, order: int = 4) -> float:
38
+ """
39
+ Richardson extrapolation for accelerating convergence
40
+ """
41
+ return (2**order * f_h - f_2h) / (2**order - 1)
42
+
43
+
44
+ # ========== Curvature Computation Class ==========
45
+
46
+ class CurvatureCalculator:
47
+ """
48
+ High-precision discrete curvature calculator using classical differential geometry
49
+ """
50
+
51
+ def __init__(self, surface: Surface, step_size: float = 1e-3):
52
+ self.surface = surface
53
+ self.h = step_size
54
+
55
+ def _compute_derivatives(self, u: float, v: float) -> Dict[str, np.ndarray]:
56
+ """使用更稳定的数值导数"""
57
+ # 避免过小的步长
58
+ effective_h = max(self.h, 1e-6)
59
+
60
+ # 使用中心差分
61
+ r_u = derivative_5pt(lambda uu: self._position_array(uu, v), u, effective_h)
62
+ r_v = derivative_5pt(lambda vv: self._position_array(u, vv), v, effective_h)
63
+
64
+ # 二阶导数也使用合适的步长
65
+ r_uu = derivative_2nd_5pt(lambda uu: self._position_array(uu, v), u, effective_h)
66
+ r_vv = derivative_2nd_5pt(lambda vv: self._position_array(u, vv), v, effective_h)
67
+ r_uv = derivative_5pt(
68
+ lambda vv: derivative_5pt(
69
+ lambda uu: self._position_array(uu, vv), u, effective_h
70
+ ), v, effective_h
71
+ )
72
+
73
+ return {
74
+ 'r_u': r_u, 'r_v': r_v,
75
+ 'r_uu': r_uu, 'r_vv': r_vv, 'r_uv': r_uv
76
+ }
77
+
78
+ def _position_array(self, u: float, v: float) -> np.ndarray:
79
+ """Convert vec3 position to numpy array"""
80
+ pos = self.surface.position(u, v)
81
+ return np.array([pos.x, pos.y, pos.z])
82
+
83
+ def compute_fundamental_forms(self, u: float, v: float) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
84
+ """
85
+ Compute first and second fundamental forms
86
+ """
87
+ derivs = self._compute_derivatives(u, v)
88
+ r_u = derivs['r_u']
89
+ r_v = derivs['r_v']
90
+ r_uu = derivs['r_uu']
91
+ r_vv = derivs['r_vv']
92
+ r_uv = derivs['r_uv']
93
+
94
+ # First fundamental form
95
+ E = np.dot(r_u, r_u)
96
+ F = np.dot(r_u, r_v)
97
+ G = np.dot(r_v, r_v)
98
+ g = np.array([[E, F], [F, G]])
99
+
100
+ # Normal vector
101
+ n_vec = np.cross(r_u, r_v)
102
+ n_norm = np.linalg.norm(n_vec)
103
+ if n_norm > 1e-14:
104
+ n = n_vec / n_norm
105
+ else:
106
+ n = np.array([0., 0., 1.])
107
+
108
+ # Second fundamental form
109
+ L = np.dot(r_uu, n)
110
+ M = np.dot(r_uv, n)
111
+ N = np.dot(r_vv, n)
112
+ h = np.array([[L, M], [M, N]])
113
+
114
+ return g, h, n
115
+
116
+ def compute_gaussian_curvature(self, u: float, v: float) -> float:
117
+ """
118
+ Compute Gaussian curvature K at a point
119
+ """
120
+ g, h, _ = self.compute_fundamental_forms(u, v)
121
+
122
+ det_g = np.linalg.det(g)
123
+ det_h = np.linalg.det(h)
124
+
125
+ if abs(det_g) < 1e-14:
126
+ return 0.0
127
+
128
+ return det_h / det_g
129
+
130
+ def compute_mean_curvature(self, u: float, v: float) -> float:
131
+ """
132
+ Compute mean curvature H at a point
133
+ """
134
+ g, h, _ = self.compute_fundamental_forms(u, v)
135
+
136
+ det_g = np.linalg.det(g)
137
+ if abs(det_g) < 1e-14:
138
+ return 0.0
139
+
140
+ trace_term = g[1,1]*h[0,0] - 2*g[0,1]*h[0,1] + g[0,0]*h[1,1]
141
+ H = trace_term / (2 * det_g)
142
+
143
+ # 对于凸曲面,平均曲率应该是正的
144
+ return abs(H)
145
+
146
+ def compute_principal_curvatures(self, u: float, v: float) -> Tuple[float, float, np.ndarray, np.ndarray]:
147
+ """
148
+ Compute principal curvatures and principal directions
149
+ """
150
+ g, h, _ = self.compute_fundamental_forms(u, v)
151
+ derivs = self._compute_derivatives(u, v)
152
+ r_u = derivs['r_u']
153
+ r_v = derivs['r_v']
154
+
155
+ det_g = np.linalg.det(g)
156
+ if abs(det_g) < 1e-14:
157
+ return 0.0, 0.0, np.array([1., 0., 0.]), np.array([0., 1., 0.])
158
+
159
+ # Shape operator S = g⁻¹h
160
+ g_inv = np.linalg.inv(g)
161
+ S = g_inv @ h
162
+
163
+ # Eigenvalue decomposition
164
+ eigenvalues, eigenvectors = np.linalg.eig(S)
165
+ k1, k2 = eigenvalues.real
166
+
167
+ # Ensure k1 >= k2 (by absolute value)
168
+ if abs(k1) < abs(k2):
169
+ k1, k2 = k2, k1
170
+ eigenvectors = eigenvectors[:, [1, 0]]
171
+
172
+ # Convert tangent plane coordinates to 3D directions
173
+ dir1_2d = eigenvectors[:, 0]
174
+ dir2_2d = eigenvectors[:, 1]
175
+
176
+ dir1_3d = dir1_2d[0] * r_u + dir1_2d[1] * r_v
177
+ dir2_3d = dir2_2d[0] * r_u + dir2_2d[1] * r_v
178
+
179
+ # Normalize
180
+ dir1_3d = dir1_3d / (np.linalg.norm(dir1_3d) + 1e-14)
181
+ dir2_3d = dir2_3d / (np.linalg.norm(dir2_3d) + 1e-14)
182
+
183
+ return k1, k2, dir1_3d, dir2_3d
184
+
185
+ def compute_all_curvatures(self, u: float, v: float) -> Dict[str, Union[float, np.ndarray]]:
186
+ """
187
+ Compute all curvature quantities at once
188
+ """
189
+ g, h, n = self.compute_fundamental_forms(u, v)
190
+ K = self.compute_gaussian_curvature(u, v)
191
+ H = self.compute_mean_curvature(u, v)
192
+ k1, k2, dir1, dir2 = self.compute_principal_curvatures(u, v)
193
+
194
+ return {
195
+ 'K': K,
196
+ 'H': H,
197
+ 'k1': k1,
198
+ 'k2': k2,
199
+ 'dir1': dir1,
200
+ 'dir2': dir2,
201
+ 'g': g,
202
+ 'h': h,
203
+ 'n': n
204
+ }
205
+
206
+
207
+ # ========== Simplified Interface Functions ==========
208
+
209
+ def gaussian_curvature_classical(surface: Surface, u: float, v: float, step_size: float = 1e-3) -> float:
210
+ """Compute Gaussian curvature using classical method"""
211
+ calc = CurvatureCalculator(surface, step_size)
212
+ return calc.compute_gaussian_curvature(u, v)
213
+
214
+ def mean_curvature_classical(surface: Surface, u: float, v: float, step_size: float = 1e-3) -> float:
215
+ """Compute mean curvature using classical method"""
216
+ calc = CurvatureCalculator(surface, step_size)
217
+ return calc.compute_mean_curvature(u, v)
218
+
219
+ def principal_curvatures_classical(surface: Surface, u: float, v: float, step_size: float = 1e-3) -> Tuple[float, float]:
220
+ """Compute principal curvatures using classical method"""
221
+ calc = CurvatureCalculator(surface, step_size)
222
+ k1, k2, _, _ = calc.compute_principal_curvatures(u, v)
223
+ return k1, k2
224
+
225
+ def all_curvatures_classical(surface: Surface, u: float, v: float, step_size: float = 1e-3) -> Dict[str, Union[float, np.ndarray]]:
226
+ """Compute all curvature quantities using classical method"""
227
+ calc = CurvatureCalculator(surface, step_size)
228
+ return calc.compute_all_curvatures(u, v)
229
+
230
+
231
+ # ========== Intrinsic Gradient Method Functions ==========
232
+
233
+ def intrinsic_gradient_gaussian_curvature(surface, u, v, step_size=1e-3):
234
+ """Compute Gaussian curvature using intrinsic gradient method"""
235
+ return compute_gaussian_curvature(surface, u, v, step_size)
236
+
237
+ def intrinsic_gradient_mean_curvature(surface, u, v, step_size=1e-3):
238
+ """Compute mean curvature using intrinsic gradient method"""
239
+ return compute_mean_curvature(surface, u, v, step_size)
240
+
241
+ def intrinsic_gradient_principal_curvatures(surface, u, v, step_size=1e-3):
242
+ """Compute principal curvatures using intrinsic gradient method"""
243
+ result = compute_all_curvatures(surface, u, v, step_size)
244
+ return result['principal_curvatures']
245
+
246
+ def intrinsic_gradient_all_curvatures(surface, u, v, step_size=1e-3):
247
+ """Compute all curvatures using intrinsic gradient method"""
248
+ return compute_all_curvatures(surface, u, v, step_size)
249
+
250
+
251
+ # ========== Method Comparison ==========
252
+
253
+ def compare_methods(surface: Surface, u: float, v: float, step_size: float = 1e-3) -> Dict[str, float]:
254
+ """
255
+ Compare classical and intrinsic gradient curvature methods
256
+ """
257
+ # Classical method
258
+ K_classical = gaussian_curvature_classical(surface, u, v, step_size)
259
+
260
+ # Intrinsic gradient method
261
+ K_intrinsic = intrinsic_gradient_gaussian_curvature(surface, u, v, step_size)
262
+
263
+ # Comparison
264
+ difference = abs(K_classical - K_intrinsic)
265
+ relative_error = difference / abs(K_classical) if abs(K_classical) > 1e-14 else 0.0
266
+
267
+ return {
268
+ 'K_classical': K_classical,
269
+ 'K_intrinsic': K_intrinsic,
270
+ 'difference': difference,
271
+ 'relative_error': relative_error
272
+ }
273
+
274
+
275
+ # ========== Backward Compatibility Functions ==========
276
+
277
+ def gaussian_curvature(surface: Surface, u: float, v: float, step_size: float = 1e-3) -> float:
278
+ """Compute Gaussian curvature (default: intrinsic gradient method)"""
279
+ return intrinsic_gradient_gaussian_curvature(surface, u, v, step_size)
280
+
281
+ def mean_curvature(surface: Surface, u: float, v: float, step_size: float = 1e-3) -> float:
282
+ """Compute mean curvature (default: intrinsic gradient method)"""
283
+ return intrinsic_gradient_mean_curvature(surface, u, v, step_size)
284
+
285
+ def principal_curvatures(surface: Surface, u: float, v: float, step_size: float = 1e-3) -> Tuple[float, float]:
286
+ """Compute principal curvatures (default: intrinsic gradient method)"""
287
+ return intrinsic_gradient_principal_curvatures(surface, u, v, step_size)
288
+
289
+ def all_curvatures(surface: Surface, u: float, v: float, step_size: float = 1e-3) -> Dict[str, Union[float, np.ndarray]]:
290
+ """Compute all curvature quantities (default: intrinsic gradient method)"""
291
+ return intrinsic_gradient_all_curvatures(surface, u, v, step_size)
292
+
293
+
294
+ # ========== Export ==========
295
+
296
+ __all__ = [
297
+ # Classical method
298
+ 'CurvatureCalculator',
299
+ 'gaussian_curvature_classical',
300
+ 'mean_curvature_classical',
301
+ 'principal_curvatures_classical',
302
+ 'all_curvatures_classical',
303
+
304
+ # Intrinsic Gradient Operator method
305
+ 'intrinsic_gradient_gaussian_curvature',
306
+ 'intrinsic_gradient_mean_curvature',
307
+ 'intrinsic_gradient_principal_curvatures',
308
+ 'intrinsic_gradient_all_curvatures',
309
+ 'compare_methods',
310
+
311
+ # Backward compatibility (default to intrinsic gradient)
312
+ 'gaussian_curvature',
313
+ 'mean_curvature',
314
+ 'principal_curvatures',
315
+ 'all_curvatures',
316
+
317
+ # Utility functions
318
+ 'derivative_5pt',
319
+ 'derivative_2nd_5pt',
320
+ 'richardson_extrapolation',
321
+ ]