Skip to content

Commit

Permalink
✨ line&plane: 添加一些笔记
Browse files Browse the repository at this point in the history
  • Loading branch information
snowykami committed Sep 6, 2024
1 parent 35537c5 commit c79f36c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
14 changes: 13 additions & 1 deletion mbcp/mp_math/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,20 @@ def cal_angle(self, other: 'Line3') -> 'AnyAngle':
return self.direction.cal_angle(other.direction)

def cal_distance(self, other: 'Line3 | Point3') -> float:
"""
r"""
计算直线和直线或点之间的距离。
:::tip
直线和直线之间的距离计算公式:
- 平行/重合 = 0
- 平行/异面 = $\frac{|\vec{P_1P_2} \times \vec{v}|}{|\vec{v}|}$
- 相交 = 0
其中,$P_1$和$P_2$分别为两条直线上的点,$\vec{v}$为直线的方向向量。
:::
:::tip
直线和点之间的距离计算公式:
$$\frac{|\vec{P_1P} \times \vec{v}|}{|\vec{v}|}$$
其中,$P_1$为直线上的点,$P$为点,$\vec{v}$为直线的方向向量。
:::
Args:
other ([`Line3`](./line#class-line3) | [`Point3`](./point#class-point3)): 另一条直线或点
Returns:
Expand Down
23 changes: 21 additions & 2 deletions mbcp/mp_math/plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,21 @@ def cal_angle(self, other: 'Line3 | Plane3') -> 'AnyAngle':
raise TypeError(f"Unsupported type: {type(other)}")

def cal_distance(self, other: 'Plane3 | Point3') -> float:
"""
r"""
计算平面与平面或点之间的距离。
:::tip
平面和平面之间的距离计算公式:
暂未实现
- 平行 = 0
- 相交 = 0
- 不平行 = $\frac{|\vec{P_1P_2} \cdot \vec{n}|}{|\vec{n}|}$
其中,$P_1$和$P_2$分别为两个平面上的点,$\vec{n}$为平面的法向量。
:::
:::tip
平面和点之间的距离计算公式:
$$\frac{|\vec{P_1P} \cdot \vec{n}|}{|\vec{n}|}$$
其中,$P_1$为平面上的点,$P$为点,$\vec{n}$为平面的法向量。
:::
Args:
other ([`Plane3`](./plane#class-plane3) | [`Point3`](./point#class-point3)): 另一个平面或点
Returns:
Expand All @@ -89,7 +102,7 @@ def cal_distance(self, other: 'Plane3 | Point3') -> float:
[`TypeError`](https%3A//docs.python.org/3/library/exceptions.html#TypeError): 不支持的类型
"""
if isinstance(other, Plane3):
return 0
raise NotImplementedError("Not implemented yet.")
elif isinstance(other, Point3):
return abs(self.a * other.x + self.b * other.y + self.c * other.z + self.d) / (self.a ** 2 + self.b ** 2 + self.c ** 2) ** 0.5
else:
Expand Down Expand Up @@ -142,6 +155,12 @@ def cal_intersection_line3(self, other: 'Plane3') -> 'Line3':
def cal_intersection_point3(self, other: 'Line3') -> 'Point3':
"""
计算平面与直线的交点。
:::tip
计算平面与直线交点的一般步骤:
1. 求直线的参数方程
2. 代入平面方程,解出t
3. 代入直线参数方程,求出交点
:::
Args:
other ([`Line3`](./line#class-line3)): 直线
Returns:
Expand Down

0 comments on commit c79f36c

Please sign in to comment.