2024-08-28 10:52:17 +08:00
|
|
|
---
|
2024-08-28 12:02:30 +08:00
|
|
|
title: mbcp.mp_math.point
|
2024-08-28 10:52:17 +08:00
|
|
|
---
|
2024-08-28 22:07:43 +08:00
|
|
|
### **class** `Point3`
|
|
|
|
### *method* `__init__(self, x: float, y: float, z: float)`
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
2024-08-28 12:02:30 +08:00
|
|
|
笛卡尔坐标系中的点。
|
2024-08-28 10:52:17 +08:00
|
|
|
|
2024-08-28 22:07:43 +08:00
|
|
|
**参数**:
|
2024-08-28 10:52:17 +08:00
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
- x: x 坐标
|
2024-08-28 10:52:17 +08:00
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
- y: y 坐标
|
|
|
|
|
|
|
|
- z: z 坐标
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<details>
|
2024-08-28 22:07:43 +08:00
|
|
|
<summary> <i>源代码</i> </summary>
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
```python
|
|
|
|
def __init__(self, x: float, y: float, z: float):
|
|
|
|
"""
|
|
|
|
笛卡尔坐标系中的点。
|
|
|
|
Args:
|
|
|
|
x: x 坐标
|
|
|
|
y: y 坐标
|
|
|
|
z: z 坐标
|
|
|
|
"""
|
|
|
|
self.x = x
|
|
|
|
self.y = y
|
|
|
|
self.z = z
|
|
|
|
```
|
|
|
|
</details>
|
|
|
|
|
2024-08-28 22:07:43 +08:00
|
|
|
### *method* `approx(self, other: Point3, epsilon: float = APPROX) -> bool`
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
2024-08-28 12:02:30 +08:00
|
|
|
判断两个点是否近似相等。
|
2024-08-28 10:52:17 +08:00
|
|
|
|
2024-08-28 22:07:43 +08:00
|
|
|
**参数**:
|
2024-08-28 10:52:17 +08:00
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
- other:
|
|
|
|
|
|
|
|
- epsilon:
|
2024-08-28 10:52:17 +08:00
|
|
|
|
2024-08-28 22:07:43 +08:00
|
|
|
**返回**:
|
|
|
|
|
|
|
|
- 是否近似相等
|
|
|
|
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
<details>
|
2024-08-28 22:07:43 +08:00
|
|
|
<summary> <i>源代码</i> </summary>
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
```python
|
|
|
|
def approx(self, other: 'Point3', epsilon: float=APPROX) -> bool:
|
|
|
|
"""
|
|
|
|
判断两个点是否近似相等。
|
|
|
|
Args:
|
|
|
|
other:
|
|
|
|
epsilon:
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
是否近似相等
|
|
|
|
"""
|
|
|
|
return all([abs(self.x - other.x) < epsilon, abs(self.y - other.y) < epsilon, abs(self.z - other.z) < epsilon])
|
|
|
|
```
|
|
|
|
</details>
|
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
### `@overload`
|
2024-08-28 22:07:43 +08:00
|
|
|
### *method* `self + other: Vector3 => Point3`
|
2024-08-28 21:27:52 +08:00
|
|
|
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
<details>
|
2024-08-28 22:07:43 +08:00
|
|
|
<summary> <i>源代码</i> </summary>
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
```python
|
|
|
|
@overload
|
|
|
|
def __add__(self, other: 'Vector3') -> 'Point3':
|
|
|
|
...
|
|
|
|
```
|
|
|
|
</details>
|
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
### `@overload`
|
2024-08-28 22:07:43 +08:00
|
|
|
### *method* `self + other: Point3 => Point3`
|
2024-08-28 21:27:52 +08:00
|
|
|
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
<details>
|
2024-08-28 22:07:43 +08:00
|
|
|
<summary> <i>源代码</i> </summary>
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
```python
|
|
|
|
@overload
|
|
|
|
def __add__(self, other: 'Point3') -> 'Point3':
|
|
|
|
...
|
|
|
|
```
|
|
|
|
</details>
|
|
|
|
|
2024-08-28 22:07:43 +08:00
|
|
|
### *method* `self + other`
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
P + V -> P
|
|
|
|
P + P -> P
|
|
|
|
|
2024-08-28 22:07:43 +08:00
|
|
|
**参数**:
|
2024-08-28 12:02:30 +08:00
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
- other:
|
|
|
|
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
<details>
|
2024-08-28 22:07:43 +08:00
|
|
|
<summary> <i>源代码</i> </summary>
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
```python
|
|
|
|
def __add__(self, other):
|
|
|
|
"""
|
|
|
|
P + V -> P
|
|
|
|
P + P -> P
|
|
|
|
Args:
|
|
|
|
other:
|
|
|
|
Returns:
|
|
|
|
"""
|
|
|
|
return Point3(self.x + other.x, self.y + other.y, self.z + other.z)
|
|
|
|
```
|
|
|
|
</details>
|
|
|
|
|
2024-08-28 22:07:43 +08:00
|
|
|
### *method* `__eq__(self, other)`
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
判断两个点是否相等。
|
|
|
|
|
2024-08-28 22:07:43 +08:00
|
|
|
**参数**:
|
2024-08-28 12:02:30 +08:00
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
- other:
|
|
|
|
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
<details>
|
2024-08-28 22:07:43 +08:00
|
|
|
<summary> <i>源代码</i> </summary>
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
```python
|
|
|
|
def __eq__(self, other):
|
|
|
|
"""
|
|
|
|
判断两个点是否相等。
|
|
|
|
Args:
|
|
|
|
other:
|
|
|
|
Returns:
|
|
|
|
"""
|
|
|
|
return approx(self.x, other.x) and approx(self.y, other.y) and approx(self.z, other.z)
|
|
|
|
```
|
|
|
|
</details>
|
|
|
|
|
2024-08-28 22:07:43 +08:00
|
|
|
### *method* `self - other: Point3 => Vector3`
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
P - P -> V
|
|
|
|
|
|
|
|
P - V -> P 已在 :class:`Vector3` 中实现
|
|
|
|
|
2024-08-28 22:07:43 +08:00
|
|
|
**参数**:
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
|
|
- other:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<details>
|
2024-08-28 22:07:43 +08:00
|
|
|
<summary> <i>源代码</i> </summary>
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
|
|
```python
|
|
|
|
def __sub__(self, other: 'Point3') -> 'Vector3':
|
|
|
|
"""
|
|
|
|
P - P -> V
|
|
|
|
|
|
|
|
P - V -> P 已在 :class:`Vector3` 中实现
|
|
|
|
Args:
|
|
|
|
other:
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
from .vector import Vector3
|
|
|
|
return Vector3(self.x - other.x, self.y - other.y, self.z - other.z)
|
|
|
|
```
|
|
|
|
</details>
|
|
|
|
|