请按照科研工程型 Python 工具库风格写代码:文件开头写模块说明、数据格式约定和注意事项;每个函数写详细中文 docstring,说明功能、几何/算法直觉、核心公式、输入输出和计算步骤;代码内部用中文注释标出关键阶段;变量命名清晰;使用 NumPy;注意数值稳定性和退化情况;基础函数在前,组合函数在后,最后提供统一接口;返回结果结构化,方便实验、汇报和模块复用。比如下面示例:
三维圆周距离计算
def point_to_circle_distance_3d(points, center, radius, normal):
"""
计算三维空间中点到圆周的距离误差,并将其分解为轴向和径向两个分量。
三维圆周由圆心 C、法向量 n(定义圆所在平面)和半径 r 三个参数确定。
点 P 到圆周的距离通过两步分解计算
1.轴向误差------点到圆所在平面的距离
2.径向误差------将 P 投影到圆平面后,投影点 P' 到圆周的距离
总误差------两分量的欧氏合成。
"""
n = normal / (np.linalg.norm(normal) + 1e-12)
轴向误差:调用点到平面距离函数
d_axial = point_to_plane_distance_3d(points, center, normal)
将 P 投影到圆平面
vec = points - center
signed_axial = np.dot(vec, n)
proj = points - signed_axial * n
P' 到圆心的距离(平面内径向距离)
dist_proj_to_center = np.linalg.norm(proj - center)
径向误差 = 投影点到圆心的距离与半径之差的绝对值
d_radial = float(abs(dist_proj_to_center - radius))
总误差:轴向误差与径向误差的欧氏合成(两分量相互正交)
d_total = float(np.sqrt(d_axial ** 2 + d_radial ** 2))
return d_total, d_axial, d_radial