flkit 0.1.0__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 (62) hide show
  1. flkit-0.1.0/.python-version +1 -0
  2. flkit-0.1.0/PKG-INFO +186 -0
  3. flkit-0.1.0/README.md +160 -0
  4. flkit-0.1.0/pyproject.toml +31 -0
  5. flkit-0.1.0/src/flkit/__init__.py +2 -0
  6. flkit-0.1.0/src/flkit/alg/__init__.py +68 -0
  7. flkit-0.1.0/src/flkit/alg/build_idx.py +9 -0
  8. flkit-0.1.0/src/flkit/alg/c_track.py +88 -0
  9. flkit-0.1.0/src/flkit/alg/collierydb.py +1217 -0
  10. flkit-0.1.0/src/flkit/alg/del2.py +421 -0
  11. flkit-0.1.0/src/flkit/alg/delaunay_triangulation.py +476 -0
  12. flkit-0.1.0/src/flkit/alg/finite_plane_distance.py +239 -0
  13. flkit-0.1.0/src/flkit/alg/get_up_low.py +32 -0
  14. flkit-0.1.0/src/flkit/alg/in_tin.py +139 -0
  15. flkit-0.1.0/src/flkit/alg/index.py +9 -0
  16. flkit-0.1.0/src/flkit/alg/inter/BasePredictor.py +69 -0
  17. flkit-0.1.0/src/flkit/alg/inter/Kriging.py +226 -0
  18. flkit-0.1.0/src/flkit/alg/inter/KrigingM.py +262 -0
  19. flkit-0.1.0/src/flkit/alg/inter/LossFuncs.py +164 -0
  20. flkit-0.1.0/src/flkit/alg/inter/__init__.py +178 -0
  21. flkit-0.1.0/src/flkit/alg/inter/idw.py +253 -0
  22. flkit-0.1.0/src/flkit/alg/inter/midw.py +145 -0
  23. flkit-0.1.0/src/flkit/alg/inter/nearest_neighbor.py +445 -0
  24. flkit-0.1.0/src/flkit/alg/inter/rbf.py +345 -0
  25. flkit-0.1.0/src/flkit/alg/inter/trilinear.py +572 -0
  26. flkit-0.1.0/src/flkit/alg/point_in_polygon.py +126 -0
  27. flkit-0.1.0/src/flkit/alg/point_in_volume.py +188 -0
  28. flkit-0.1.0/src/flkit/alg/point_in_volume_rs.pyi +7 -0
  29. flkit-0.1.0/src/flkit/alg/point_to_triangle.py +116 -0
  30. flkit-0.1.0/src/flkit/alg/point_to_triangle_mesh.py +309 -0
  31. flkit-0.1.0/src/flkit/alg/point_to_triangle_rs.pyi +9 -0
  32. flkit-0.1.0/src/flkit/alg/rotated_rect.py +184 -0
  33. flkit-0.1.0/src/flkit/db/__init__.py +17 -0
  34. flkit-0.1.0/src/flkit/db/db_model.py +724 -0
  35. flkit-0.1.0/src/flkit/db/duck_model.py +151 -0
  36. flkit-0.1.0/src/flkit/db/fileobj.py +72 -0
  37. flkit-0.1.0/src/flkit/db/path_utl.py +174 -0
  38. flkit-0.1.0/src/flkit/mtcli/__init__.py +18 -0
  39. flkit-0.1.0/src/flkit/mtcli/core.py +489 -0
  40. flkit-0.1.0/src/flkit/mtcli/parse.py +218 -0
  41. flkit-0.1.0/src/flkit/py.typed +0 -0
  42. flkit-0.1.0/src/flkit/tools/__init__.py +28 -0
  43. flkit-0.1.0/src/flkit/tools/del_key.py +13 -0
  44. flkit-0.1.0/src/flkit/tools/dict_to_list.py +10 -0
  45. flkit-0.1.0/src/flkit/tools/get_region.py +42 -0
  46. flkit-0.1.0/src/flkit/tools/max_key.py +7 -0
  47. flkit-0.1.0/src/flkit/tools/mongo.py +119 -0
  48. flkit-0.1.0/src/flkit/tools/mt_dash.py +121 -0
  49. flkit-0.1.0/src/flkit/tools/prase_type.py +27 -0
  50. flkit-0.1.0/src/flkit/typr/Res.py +21 -0
  51. flkit-0.1.0/src/flkit/typr/__init__.py +107 -0
  52. flkit-0.1.0/src/flkit/typr/c_grid.py +425 -0
  53. flkit-0.1.0/src/flkit/typr/console.py +283 -0
  54. flkit-0.1.0/src/flkit/typr/engine.py +59 -0
  55. flkit-0.1.0/src/flkit/typr/getenv.py +89 -0
  56. flkit-0.1.0/src/flkit/typr/result.py +81 -0
  57. flkit-0.1.0/src/flkit/typr/table.py +34 -0
  58. flkit-0.1.0/src/flkit/typr/utils.py +542 -0
  59. flkit-0.1.0/src/flkit/typr/verify.py +64 -0
  60. flkit-0.1.0/src/flkit/typr/webview.py +219 -0
  61. flkit-0.1.0/src/flkit/typr/wstask.py +344 -0
  62. flkit-0.1.0/uv.lock +1257 -0
@@ -0,0 +1 @@
1
+ 3.13
flkit-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,186 @@
1
+ Metadata-Version: 2.4
2
+ Name: flkit
3
+ Version: 0.1.0
4
+ Summary: 一个功能强大的 Python 工具包,提供空间分析、数据插值、数据库操作、命令行工具等多种功能
5
+ Requires-Python: >=3.13
6
+ Requires-Dist: click>=8.1.0
7
+ Requires-Dist: duckdb>=1.5.1
8
+ Requires-Dist: fastapi>=0.135.2
9
+ Requires-Dist: matplotlib>=3.10.8
10
+ Requires-Dist: numpy>=2.4.4
11
+ Requires-Dist: opencv-python>=4.13.0.92
12
+ Requires-Dist: pandas>=3.0.1
13
+ Requires-Dist: pexpect>=4.8.0
14
+ Requires-Dist: pydantic>=2.0.0
15
+ Requires-Dist: pykrige>=1.7.3
16
+ Requires-Dist: pymongo>=4.16.0
17
+ Requires-Dist: python-dotenv>=1.0.0
18
+ Requires-Dist: pyvista>=0.47.1
19
+ Requires-Dist: pyvistaqt>=0.11.3
20
+ Requires-Dist: pywebview>=6.1
21
+ Requires-Dist: requests>=2.31.0
22
+ Requires-Dist: scikit-learn>=1.3.0
23
+ Requires-Dist: scipy>=1.17.1
24
+ Requires-Dist: triangle>=20250106
25
+ Description-Content-Type: text/markdown
26
+
27
+ # flkit
28
+
29
+ 一个功能强大的 Python 工具包,提供空间分析、数据插值、数据库操作、命令行工具等多种功能。
30
+
31
+ ## 功能特性
32
+
33
+ ### 空间分析算法 (flkit.alg)
34
+ - **三角剖分**: Delaunay 三角剖分算法
35
+ - **点与几何体关系**: 点在三角形内、点在多边形内、点在体积内等判断
36
+ - **距离计算**: 有限平面距离、点到三角形距离等
37
+ - **追踪算法**: 曲线追踪和方向计算
38
+ - **索引构建**: 空间索引构建和查询
39
+
40
+ ### 数据插值方法 (flkit.alg.inter)
41
+ - **IDW**: 反距离加权插值(2D/3D)
42
+ - **Kriging**: 克里金插值(普通克里金、泛克里金)
43
+ - **RBF**: 径向基函数插值
44
+ - **最近邻**: 最近邻插值
45
+ - **三线性**: 三线性插值
46
+ - **MIDW**: 改进的 IDW 插值方法
47
+
48
+ ### 数据库操作 (flkit.db)
49
+ - **MongoDB**: MongoDB 数据库连接和操作
50
+ - **DuckDB**: DuckDB 嵌入式数据库支持
51
+ - **文件数据库**: 文件对象数据库管理
52
+ - **路径工具**: 路径处理和压缩工具
53
+
54
+ ### 命令行工具 (flkit.mtcli)
55
+ - **命令解析**: 灵活的命令行参数解析
56
+ - **命令组**: 支持命令分组和嵌套
57
+ - **上下文管理**: 命令执行上下文管理
58
+
59
+ ### 实用工具 (flkit.tools)
60
+ - **MongoDB 管理**: MongoDB 进程管理
61
+ - **区域查询**: 地理区域查询
62
+ - **数据转换**: 字典与列表转换
63
+ - **MongoDB 客户端**: 命令行 MongoDB 客户端
64
+
65
+ ### 类型系统 (flkit.typr)
66
+ - **结果处理**: 统一的结果处理和错误管理
67
+ - **控制台**: 控制台命令执行
68
+ - **网格系统**: 2D/3D 网格管理
69
+ - **Web 视图**: 桌面应用 Web 视图
70
+ - **环境变量**: 环境变量管理
71
+ - **验证**: 数据验证工具
72
+ - **WebSocket**: WebSocket 任务处理
73
+
74
+ ## 安装
75
+
76
+ ### 环境要求
77
+ - Python >= 3.13
78
+
79
+ ### 安装依赖
80
+
81
+ ```bash
82
+ pip install numpy scipy pandas pykrige triangle pymongo duckdb pyvista pyvistaqt matplotlib opencv-python fastapi requests pywebview click pexpect pydantic python-dotenv scikit-learn
83
+ ```
84
+
85
+ 或使用版本约束:
86
+
87
+ ```bash
88
+ pip install "numpy>=1.24.0" "scipy>=1.10.0" "pandas>=2.0.0" "pykrige>=1.7.0" "triangle>=20230923" "pymongo>=4.0.0" "duckdb>=0.9.0" "pyvista>=0.40.0" "pyvistaqt>=0.10.0" "matplotlib>=3.7.0" "opencv-python>=4.8.0" "fastapi>=0.100.0" "requests>=2.31.0" "pywebview>=4.0.0" "click>=8.1.0" "pexpect>=4.8.0" "pydantic>=2.0.0" "python-dotenv>=1.0.0" "scikit-learn>=1.3.0"
89
+ ```
90
+
91
+ ### 安装 flkit
92
+
93
+ ```bash
94
+ pip install -e .
95
+ ```
96
+
97
+ ## 快速开始
98
+
99
+ ### 空间插值示例
100
+
101
+ ```python
102
+ import numpy as np
103
+ from flkit.alg.inter import Kriging2D, IDW2D
104
+
105
+ # 创建已知点数据
106
+ points = np.array([
107
+ [0, 0, 10],
108
+ [1, 0, 15],
109
+ [0, 1, 12],
110
+ [1, 1, 18]
111
+ ])
112
+
113
+ # 使用克里金插值
114
+ kriging = Kriging2D(variogram_model="spherical")
115
+ kriging.fit(points)
116
+
117
+ # 预测新点的值
118
+ new_point = np.array([0.5, 0.5])
119
+ predicted_value = kriging.predict(new_point)
120
+ print(f"预测值: {predicted_value}")
121
+ ```
122
+
123
+ ### 数据库操作示例
124
+
125
+ ```python
126
+ from flkit.db import MongoDBConnector
127
+
128
+ # 连接 MongoDB
129
+ connector = MongoDBConnector("mongodb://localhost:27017", "mydb")
130
+
131
+ # 插入数据
132
+ collection = connector.get_collection("users")
133
+ collection.insert_one({"name": "张三", "age": 25})
134
+ ```
135
+
136
+ ### 命令行工具示例
137
+
138
+ ```python
139
+ from flkit.typr import command, run_cmd
140
+ from typing import Optional
141
+
142
+ @command
143
+ def greet(name: str, count: int = 1):
144
+ """问候命令"""
145
+ for _ in range(count):
146
+ print(f"你好, {name}!")
147
+
148
+ if __name__ == "__main__":
149
+ run_cmd(greet)
150
+ ```
151
+
152
+ ## 项目结构
153
+
154
+ ```
155
+ flkit/
156
+ ├── alg/ # 空间分析算法
157
+ │ ├── inter/ # 插值方法
158
+ │ └── ...
159
+ ├── db/ # 数据库操作
160
+ ├── mtcli/ # 命令行工具
161
+ ├── tools/ # 实用工具
162
+ └── typr/ # 类型系统和工具
163
+ ```
164
+
165
+ ## 依赖库
166
+
167
+ ### 核心依赖
168
+ - numpy, scipy, pandas - 数据科学基础
169
+ - pykrige - 克里金插值
170
+ - triangle - 三角剖分
171
+ - pymongo, duckdb - 数据库
172
+ - pyvista, pyvistaqt - 3D 可视化
173
+ - matplotlib - 2D 绘图
174
+ - opencv-python - 图像处理
175
+ - fastapi, requests, pywebview - Web 和网络
176
+ - click, pexpect - 命令行工具
177
+ - pydantic, python-dotenv - 数据验证和配置
178
+ - scikit-learn - 机器学习
179
+
180
+ ## 许可证
181
+
182
+ 请查看项目许可证文件。
183
+
184
+ ## 贡献
185
+
186
+ 欢迎提交 Issue 和 Pull Request!
flkit-0.1.0/README.md ADDED
@@ -0,0 +1,160 @@
1
+ # flkit
2
+
3
+ 一个功能强大的 Python 工具包,提供空间分析、数据插值、数据库操作、命令行工具等多种功能。
4
+
5
+ ## 功能特性
6
+
7
+ ### 空间分析算法 (flkit.alg)
8
+ - **三角剖分**: Delaunay 三角剖分算法
9
+ - **点与几何体关系**: 点在三角形内、点在多边形内、点在体积内等判断
10
+ - **距离计算**: 有限平面距离、点到三角形距离等
11
+ - **追踪算法**: 曲线追踪和方向计算
12
+ - **索引构建**: 空间索引构建和查询
13
+
14
+ ### 数据插值方法 (flkit.alg.inter)
15
+ - **IDW**: 反距离加权插值(2D/3D)
16
+ - **Kriging**: 克里金插值(普通克里金、泛克里金)
17
+ - **RBF**: 径向基函数插值
18
+ - **最近邻**: 最近邻插值
19
+ - **三线性**: 三线性插值
20
+ - **MIDW**: 改进的 IDW 插值方法
21
+
22
+ ### 数据库操作 (flkit.db)
23
+ - **MongoDB**: MongoDB 数据库连接和操作
24
+ - **DuckDB**: DuckDB 嵌入式数据库支持
25
+ - **文件数据库**: 文件对象数据库管理
26
+ - **路径工具**: 路径处理和压缩工具
27
+
28
+ ### 命令行工具 (flkit.mtcli)
29
+ - **命令解析**: 灵活的命令行参数解析
30
+ - **命令组**: 支持命令分组和嵌套
31
+ - **上下文管理**: 命令执行上下文管理
32
+
33
+ ### 实用工具 (flkit.tools)
34
+ - **MongoDB 管理**: MongoDB 进程管理
35
+ - **区域查询**: 地理区域查询
36
+ - **数据转换**: 字典与列表转换
37
+ - **MongoDB 客户端**: 命令行 MongoDB 客户端
38
+
39
+ ### 类型系统 (flkit.typr)
40
+ - **结果处理**: 统一的结果处理和错误管理
41
+ - **控制台**: 控制台命令执行
42
+ - **网格系统**: 2D/3D 网格管理
43
+ - **Web 视图**: 桌面应用 Web 视图
44
+ - **环境变量**: 环境变量管理
45
+ - **验证**: 数据验证工具
46
+ - **WebSocket**: WebSocket 任务处理
47
+
48
+ ## 安装
49
+
50
+ ### 环境要求
51
+ - Python >= 3.13
52
+
53
+ ### 安装依赖
54
+
55
+ ```bash
56
+ pip install numpy scipy pandas pykrige triangle pymongo duckdb pyvista pyvistaqt matplotlib opencv-python fastapi requests pywebview click pexpect pydantic python-dotenv scikit-learn
57
+ ```
58
+
59
+ 或使用版本约束:
60
+
61
+ ```bash
62
+ pip install "numpy>=1.24.0" "scipy>=1.10.0" "pandas>=2.0.0" "pykrige>=1.7.0" "triangle>=20230923" "pymongo>=4.0.0" "duckdb>=0.9.0" "pyvista>=0.40.0" "pyvistaqt>=0.10.0" "matplotlib>=3.7.0" "opencv-python>=4.8.0" "fastapi>=0.100.0" "requests>=2.31.0" "pywebview>=4.0.0" "click>=8.1.0" "pexpect>=4.8.0" "pydantic>=2.0.0" "python-dotenv>=1.0.0" "scikit-learn>=1.3.0"
63
+ ```
64
+
65
+ ### 安装 flkit
66
+
67
+ ```bash
68
+ pip install -e .
69
+ ```
70
+
71
+ ## 快速开始
72
+
73
+ ### 空间插值示例
74
+
75
+ ```python
76
+ import numpy as np
77
+ from flkit.alg.inter import Kriging2D, IDW2D
78
+
79
+ # 创建已知点数据
80
+ points = np.array([
81
+ [0, 0, 10],
82
+ [1, 0, 15],
83
+ [0, 1, 12],
84
+ [1, 1, 18]
85
+ ])
86
+
87
+ # 使用克里金插值
88
+ kriging = Kriging2D(variogram_model="spherical")
89
+ kriging.fit(points)
90
+
91
+ # 预测新点的值
92
+ new_point = np.array([0.5, 0.5])
93
+ predicted_value = kriging.predict(new_point)
94
+ print(f"预测值: {predicted_value}")
95
+ ```
96
+
97
+ ### 数据库操作示例
98
+
99
+ ```python
100
+ from flkit.db import MongoDBConnector
101
+
102
+ # 连接 MongoDB
103
+ connector = MongoDBConnector("mongodb://localhost:27017", "mydb")
104
+
105
+ # 插入数据
106
+ collection = connector.get_collection("users")
107
+ collection.insert_one({"name": "张三", "age": 25})
108
+ ```
109
+
110
+ ### 命令行工具示例
111
+
112
+ ```python
113
+ from flkit.typr import command, run_cmd
114
+ from typing import Optional
115
+
116
+ @command
117
+ def greet(name: str, count: int = 1):
118
+ """问候命令"""
119
+ for _ in range(count):
120
+ print(f"你好, {name}!")
121
+
122
+ if __name__ == "__main__":
123
+ run_cmd(greet)
124
+ ```
125
+
126
+ ## 项目结构
127
+
128
+ ```
129
+ flkit/
130
+ ├── alg/ # 空间分析算法
131
+ │ ├── inter/ # 插值方法
132
+ │ └── ...
133
+ ├── db/ # 数据库操作
134
+ ├── mtcli/ # 命令行工具
135
+ ├── tools/ # 实用工具
136
+ └── typr/ # 类型系统和工具
137
+ ```
138
+
139
+ ## 依赖库
140
+
141
+ ### 核心依赖
142
+ - numpy, scipy, pandas - 数据科学基础
143
+ - pykrige - 克里金插值
144
+ - triangle - 三角剖分
145
+ - pymongo, duckdb - 数据库
146
+ - pyvista, pyvistaqt - 3D 可视化
147
+ - matplotlib - 2D 绘图
148
+ - opencv-python - 图像处理
149
+ - fastapi, requests, pywebview - Web 和网络
150
+ - click, pexpect - 命令行工具
151
+ - pydantic, python-dotenv - 数据验证和配置
152
+ - scikit-learn - 机器学习
153
+
154
+ ## 许可证
155
+
156
+ 请查看项目许可证文件。
157
+
158
+ ## 贡献
159
+
160
+ 欢迎提交 Issue 和 Pull Request!
@@ -0,0 +1,31 @@
1
+ [project]
2
+ name = "flkit"
3
+ version = "0.1.0"
4
+ description = "一个功能强大的 Python 工具包,提供空间分析、数据插值、数据库操作、命令行工具等多种功能"
5
+ readme = "README.md"
6
+ requires-python = ">=3.13"
7
+ dependencies = [
8
+ "duckdb>=1.5.1",
9
+ "fastapi>=0.135.2",
10
+ "matplotlib>=3.10.8",
11
+ "numpy>=2.4.4",
12
+ "opencv-python>=4.13.0.92",
13
+ "pandas>=3.0.1",
14
+ "pykrige>=1.7.3",
15
+ "pymongo>=4.16.0",
16
+ "pyvista>=0.47.1",
17
+ "pyvistaqt>=0.11.3",
18
+ "pywebview>=6.1",
19
+ "scipy>=1.17.1",
20
+ "triangle>=20250106",
21
+ "click>=8.1.0",
22
+ "pexpect>=4.8.0",
23
+ "pydantic>=2.0.0",
24
+ "python-dotenv>=1.0.0",
25
+ "scikit-learn>=1.3.0",
26
+ "requests>=2.31.0",
27
+ ]
28
+
29
+ [build-system]
30
+ requires = ["hatchling"]
31
+ build-backend = "hatchling.build"
@@ -0,0 +1,2 @@
1
+ def hello() -> str:
2
+ return "Hello from flkit!"
@@ -0,0 +1,68 @@
1
+ """
2
+ 算法库
3
+
4
+ - c_next_point: 计算钻孔轨迹的下一个拐点坐标
5
+ - get_up_low: 获取钻孔轨迹的上、下点坐标
6
+ - finite_plane_distance: 计算点到有限平面的距离
7
+ - inter: 插值算法
8
+ """
9
+
10
+ from .c_track import c_next_point, comp_towards, comp_towards_batch
11
+ from .get_up_low import get_up_low, linear_interpolation
12
+ from .finite_plane_distance import comp_sliding_diff, finite_plane_distance
13
+ from . import inter
14
+ from .in_tin import (
15
+ is_point_in_triangle,
16
+ is_point_in_triangles,
17
+ point_to_triangle_distance,
18
+ )
19
+ from .point_in_polygon import PointInPolygon
20
+ from .rotated_rect import RotatedRect
21
+ from .index import list_index
22
+ from .point_to_triangle_mesh import PointToTriangleMesh
23
+ from .delaunay_triangulation import (
24
+ DelaunayTriangulation,
25
+ OptimizedDelaunayTriangulation,
26
+ TriangleLibTriangulation,
27
+ point_in_polygon,
28
+ bound_triangulation,
29
+ interpolate_delaunary_z,
30
+ convex_hull_boundary,
31
+ )
32
+ from .point_to_triangle import PointInTriangle
33
+ from .point_to_triangle_rs import PointInTriangle as PointInTriangleRs
34
+ from .point_in_volume import PointInVolume
35
+ from .point_in_volume_rs import PointInVolume as PointInVolumeRs
36
+
37
+ from .build_idx import build_idx
38
+
39
+
40
+ __all__ = [
41
+ "c_next_point",
42
+ "comp_towards",
43
+ "comp_towards_batch",
44
+ "get_up_low",
45
+ "linear_interpolation",
46
+ "comp_sliding_diff",
47
+ "finite_plane_distance",
48
+ "inter",
49
+ "is_point_in_triangle",
50
+ "is_point_in_triangles",
51
+ "point_to_triangle_distance",
52
+ "PointInPolygon",
53
+ "RotatedRect",
54
+ "list_index",
55
+ "PointToTriangleMesh",
56
+ "DelaunayTriangulation",
57
+ "OptimizedDelaunayTriangulation",
58
+ "TriangleLibTriangulation",
59
+ "point_in_polygon",
60
+ "bound_triangulation",
61
+ "interpolate_delaunary_z",
62
+ "convex_hull_boundary",
63
+ "PointInTriangle",
64
+ "PointInTriangleRs",
65
+ "PointInVolume",
66
+ "PointInVolumeRs",
67
+ "build_idx",
68
+ ]
@@ -0,0 +1,9 @@
1
+ import pandas as pd
2
+
3
+ def build_idx(df: pd.DataFrame, idx_col: str, include_cols: list[str]) -> list:
4
+ """
5
+ 构建索引
6
+ """
7
+ df[idx_col] = df[include_cols].astype(str).agg(":", sep="").tolist()
8
+ idxs = df[idx_col].unique().tolist()
9
+ return idxs
@@ -0,0 +1,88 @@
1
+ import math
2
+ from typing import Any, Dict, List
3
+
4
+
5
+ def c_next_point(start_point, length, inclination, azimuth):
6
+ """
7
+ 计算钻孔轨迹的下一个拐点坐标
8
+
9
+ 参数:
10
+ start_point: 起点坐标 (x, y, z) 元组
11
+ length: 钻孔长度 (必须为正数)
12
+ inclination: 倾角/倾斜角 (度,-90到90度,负值表示向上)
13
+ azimuth: 方位角 (度,0-360度)
14
+
15
+ 返回:
16
+ 下一个拐点的三维坐标 (x, y, z) 元组
17
+
18
+ 坐标系约定:
19
+ - X轴:东西方向(东为正)
20
+ - Y轴:南北方向(北为正)
21
+ - Z轴:垂直方向(向下为正,符合钻孔深度增加的习惯)
22
+
23
+ 倾角约定:
24
+ - 0度:水平
25
+ - 90度:垂直向下
26
+ - -90度:垂直向上
27
+ """
28
+ if length < 0:
29
+ raise ValueError(f"钻孔长度必须为正数{length}")
30
+
31
+ # 倾角范围检查(允许负值)
32
+ if not -90 <= inclination <= 90:
33
+ raise ValueError("倾角必须在-90到90度之间")
34
+
35
+ if not 0 <= azimuth <= 360:
36
+ raise ValueError("方位角必须在0-360度之间")
37
+
38
+ # 转换为弧度
39
+ inclination_rad = math.radians(inclination)
40
+ azimuth_rad = math.radians(azimuth)
41
+
42
+ # 计算坐标增量
43
+ # 水平分量(在XY平面上的投影)
44
+ horizontal_component = length * math.cos(inclination_rad)
45
+ # 垂直分量(Z方向)
46
+ vertical_component = length * math.sin(inclination_rad)
47
+
48
+ # 分解水平分量到X和Y方向
49
+ delta_x = horizontal_component * math.sin(azimuth_rad)
50
+ delta_y = horizontal_component * math.cos(azimuth_rad)
51
+ delta_z = vertical_component
52
+
53
+ # 计算新坐标
54
+ x = start_point[0] + delta_x
55
+ y = start_point[1] + delta_y
56
+ z = start_point[2] + delta_z
57
+
58
+ return (x, y, z)
59
+
60
+
61
+ def comp_towards(start: dict, end: dict) -> float:
62
+ """计算从起点指向终点的方向角度(顺时针,以正北为0度)"""
63
+ if "x" not in start or "y" not in start or "x" not in end or "y" not in end:
64
+ raise ValueError("点必须包含x和y坐标")
65
+ dx = end["x"] - start["x"]
66
+ dy = end["y"] - start["y"]
67
+ angle = math.acos(dy / math.sqrt(dx**2 + dy**2))
68
+ return round(math.degrees(angle), 3)
69
+
70
+
71
+ def comp_towards_batch(points: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
72
+ """批量计算从起点指向终点的方向角度(顺时针,以正北为0度)"""
73
+ if len(points) < 2:
74
+ raise ValueError("点列表长度必须大于等于2")
75
+
76
+ blocks = []
77
+ for i in range(len(points) - 1):
78
+ block = {
79
+ "start": points[i],
80
+ "end": points[i + 1],
81
+ }
82
+ blocks.append(block)
83
+
84
+ for block in blocks:
85
+ angle = comp_towards(block["start"], block["end"])
86
+ block["angle"] = angle
87
+
88
+ return blocks