mirror of
https://github.com/snowykami/mbcp.git
synced 2024-11-22 06:07:37 +08:00
📝 构建文档测试
This commit is contained in:
parent
84f8228f3b
commit
eb6e309b0d
@ -1,3 +0,0 @@
|
||||
---
|
||||
title: mbcp
|
||||
---
|
@ -1,399 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.angle
|
||||
---
|
||||
### **class** `Angle`
|
||||
### **class** `AnyAngle(Angle)`
|
||||
### *method* `__init__(self, value: float, is_radian: bool = False)`
|
||||
|
||||
|
||||
|
||||
**Description**: 任意角度。
|
||||
|
||||
**Arguments**:
|
||||
> - value: 角度或弧度值
|
||||
> - is_radian: 是否为弧度,默认为否
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, value: float, is_radian: bool=False):
|
||||
"""
|
||||
任意角度。
|
||||
Args:
|
||||
value: 角度或弧度值
|
||||
is_radian: 是否为弧度,默认为否
|
||||
"""
|
||||
if is_radian:
|
||||
self.radian = value
|
||||
else:
|
||||
self.radian = value * PI / 180
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `complementary(self) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**Description**: 余角:两角的和为90°。
|
||||
|
||||
**Return**: 余角
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def complementary(self) -> 'AnyAngle':
|
||||
"""
|
||||
余角:两角的和为90°。
|
||||
Returns:
|
||||
余角
|
||||
"""
|
||||
return AnyAngle(PI / 2 - self.minimum_positive.radian, is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `supplementary(self) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**Description**: 补角:两角的和为180°。
|
||||
|
||||
**Return**: 补角
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def supplementary(self) -> 'AnyAngle':
|
||||
"""
|
||||
补角:两角的和为180°。
|
||||
Returns:
|
||||
补角
|
||||
"""
|
||||
return AnyAngle(PI - self.minimum_positive.radian, is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `degree(self) -> float`
|
||||
|
||||
|
||||
|
||||
**Description**: 角度。
|
||||
|
||||
**Return**: 弧度
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def degree(self) -> float:
|
||||
"""
|
||||
角度。
|
||||
Returns:
|
||||
弧度
|
||||
"""
|
||||
return self.radian * 180 / PI
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `minimum_positive(self) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**Description**: 最小正角。
|
||||
|
||||
**Return**: 最小正角度
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def minimum_positive(self) -> 'AnyAngle':
|
||||
"""
|
||||
最小正角。
|
||||
Returns:
|
||||
最小正角度
|
||||
"""
|
||||
return AnyAngle(self.radian % (2 * PI))
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `maximum_negative(self) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**Description**: 最大负角。
|
||||
|
||||
**Return**: 最大负角度
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def maximum_negative(self) -> 'AnyAngle':
|
||||
"""
|
||||
最大负角。
|
||||
Returns:
|
||||
最大负角度
|
||||
"""
|
||||
return AnyAngle(-self.radian % (2 * PI), is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `sin(self) -> float`
|
||||
|
||||
|
||||
|
||||
**Description**: 正弦值。
|
||||
|
||||
**Return**: 正弦值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def sin(self) -> float:
|
||||
"""
|
||||
正弦值。
|
||||
Returns:
|
||||
正弦值
|
||||
"""
|
||||
return math.sin(self.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `cos(self) -> float`
|
||||
|
||||
|
||||
|
||||
**Description**: 余弦值。
|
||||
|
||||
**Return**: 余弦值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def cos(self) -> float:
|
||||
"""
|
||||
余弦值。
|
||||
Returns:
|
||||
余弦值
|
||||
"""
|
||||
return math.cos(self.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `tan(self) -> float`
|
||||
|
||||
|
||||
|
||||
**Description**: 正切值。
|
||||
|
||||
**Return**: 正切值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def tan(self) -> float:
|
||||
"""
|
||||
正切值。
|
||||
Returns:
|
||||
正切值
|
||||
"""
|
||||
return math.tan(self.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `cot(self) -> float`
|
||||
|
||||
|
||||
|
||||
**Description**: 余切值。
|
||||
|
||||
**Return**: 余切值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def cot(self) -> float:
|
||||
"""
|
||||
余切值。
|
||||
Returns:
|
||||
余切值
|
||||
"""
|
||||
return 1 / math.tan(self.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `sec(self) -> float`
|
||||
|
||||
|
||||
|
||||
**Description**: 正割值。
|
||||
|
||||
**Return**: 正割值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def sec(self) -> float:
|
||||
"""
|
||||
正割值。
|
||||
Returns:
|
||||
正割值
|
||||
"""
|
||||
return 1 / math.cos(self.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `csc(self) -> float`
|
||||
|
||||
|
||||
|
||||
**Description**: 余割值。
|
||||
|
||||
**Return**: 余割值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def csc(self) -> float:
|
||||
"""
|
||||
余割值。
|
||||
Returns:
|
||||
余割值
|
||||
"""
|
||||
return 1 / math.sin(self.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self + other: AnyAngle => AnyAngle`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __add__(self, other: 'AnyAngle') -> 'AnyAngle':
|
||||
return AnyAngle(self.radian + other.radian, is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__eq__(self, other)`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __eq__(self, other):
|
||||
return approx(self.radian, other.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self - other: AnyAngle => AnyAngle`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __sub__(self, other: 'AnyAngle') -> 'AnyAngle':
|
||||
return AnyAngle(self.radian - other.radian, is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self * other: float => AnyAngle`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __mul__(self, other: float) -> 'AnyAngle':
|
||||
return AnyAngle(self.radian * other, is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self / other: float => AnyAngle`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __truediv__(self, other: float) -> 'AnyAngle':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self / other: AnyAngle => float`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __truediv__(self, other: 'AnyAngle') -> float:
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self / other`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __truediv__(self, other):
|
||||
if isinstance(other, AnyAngle):
|
||||
return self.radian / other.radian
|
||||
return AnyAngle(self.radian / other, is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
@ -1,3 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.const
|
||||
---
|
@ -1,151 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.equation
|
||||
---
|
||||
### *func* `get_partial_derivative_func(func: MultiVarsFunc = EPSILON) -> MultiVarsFunc`
|
||||
|
||||
|
||||
|
||||
**Description**: 求N元函数一阶偏导函数。这玩意不太稳定,慎用。
|
||||
|
||||
**Arguments**:
|
||||
> - func: 函数
|
||||
> - var: 变量位置,可为整数(一阶偏导)或整数元组(高阶偏导)
|
||||
> - epsilon: 偏移量
|
||||
|
||||
**Return**: 偏导函数
|
||||
|
||||
**Raises**:
|
||||
> - ValueError 无效变量类型
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def get_partial_derivative_func(func: MultiVarsFunc, var: int | tuple[int, ...], epsilon: Number=EPSILON) -> MultiVarsFunc:
|
||||
"""
|
||||
求N元函数一阶偏导函数。这玩意不太稳定,慎用。
|
||||
Args:
|
||||
func: 函数
|
||||
var: 变量位置,可为整数(一阶偏导)或整数元组(高阶偏导)
|
||||
epsilon: 偏移量
|
||||
Returns:
|
||||
偏导函数
|
||||
Raises:
|
||||
ValueError: 无效变量类型
|
||||
"""
|
||||
if isinstance(var, int):
|
||||
|
||||
def partial_derivative_func(*args: Var) -> Var:
|
||||
args_list_plus = list(args)
|
||||
args_list_plus[var] += epsilon
|
||||
args_list_minus = list(args)
|
||||
args_list_minus[var] -= epsilon
|
||||
return (func(*args_list_plus) - func(*args_list_minus)) / (2 * epsilon)
|
||||
return partial_derivative_func
|
||||
elif isinstance(var, tuple):
|
||||
|
||||
def high_order_partial_derivative_func(*args: Var) -> Var:
|
||||
result_func = func
|
||||
for v in var:
|
||||
result_func = get_partial_derivative_func(result_func, v, epsilon)
|
||||
return result_func(*args)
|
||||
return high_order_partial_derivative_func
|
||||
else:
|
||||
raise ValueError('Invalid var type')
|
||||
```
|
||||
</details>
|
||||
|
||||
### *func* `partial_derivative_func() -> Var`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def partial_derivative_func(*args: Var) -> Var:
|
||||
args_list_plus = list(args)
|
||||
args_list_plus[var] += epsilon
|
||||
args_list_minus = list(args)
|
||||
args_list_minus[var] -= epsilon
|
||||
return (func(*args_list_plus) - func(*args_list_minus)) / (2 * epsilon)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *func* `high_order_partial_derivative_func() -> Var`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def high_order_partial_derivative_func(*args: Var) -> Var:
|
||||
result_func = func
|
||||
for v in var:
|
||||
result_func = get_partial_derivative_func(result_func, v, epsilon)
|
||||
return result_func(*args)
|
||||
```
|
||||
</details>
|
||||
|
||||
### **class** `CurveEquation`
|
||||
### *method* `__init__(self, x_func: OneVarFunc, y_func: OneVarFunc, z_func: OneVarFunc)`
|
||||
|
||||
|
||||
|
||||
**Description**: 曲线方程。
|
||||
|
||||
**Arguments**:
|
||||
> - x_func: x函数
|
||||
> - y_func: y函数
|
||||
> - z_func: z函数
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, x_func: OneVarFunc, y_func: OneVarFunc, z_func: OneVarFunc):
|
||||
"""
|
||||
曲线方程。
|
||||
Args:
|
||||
x_func: x函数
|
||||
y_func: y函数
|
||||
z_func: z函数
|
||||
"""
|
||||
self.x_func = x_func
|
||||
self.y_func = y_func
|
||||
self.z_func = z_func
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__call__(self) -> Point3 | tuple[Point3, ...]`
|
||||
|
||||
|
||||
|
||||
**Description**: 计算曲线上的点。
|
||||
|
||||
**Arguments**:
|
||||
> - *t:
|
||||
> - 参数:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __call__(self, *t: Var) -> Point3 | tuple[Point3, ...]:
|
||||
"""
|
||||
计算曲线上的点。
|
||||
Args:
|
||||
*t:
|
||||
参数
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if len(t) == 1:
|
||||
return Point3(self.x_func(t[0]), self.y_func(t[0]), self.z_func(t[0]))
|
||||
else:
|
||||
return tuple([Point3(x, y, z) for x, y, z in zip(self.x_func(t), self.y_func(t), self.z_func(t))])
|
||||
```
|
||||
</details>
|
||||
|
@ -1,3 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math
|
||||
---
|
@ -1,530 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.line
|
||||
---
|
||||
### **class** `Line3`
|
||||
### *method* `__init__(self, point: Point3, direction: Vector3)`
|
||||
|
||||
|
||||
|
||||
**Description**: 三维空间中的直线。由一个点和一个方向向量确定。
|
||||
|
||||
**Arguments**:
|
||||
> - point: 直线上的一点
|
||||
> - direction: 直线的方向向量
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, point: 'Point3', direction: 'Vector3'):
|
||||
"""
|
||||
三维空间中的直线。由一个点和一个方向向量确定。
|
||||
Args:
|
||||
point: 直线上的一点
|
||||
direction: 直线的方向向量
|
||||
"""
|
||||
self.point = point
|
||||
self.direction = direction
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `approx(self, other: Line3, epsilon: float = APPROX) -> bool`
|
||||
|
||||
|
||||
|
||||
**Description**: 判断两条直线是否近似相等。
|
||||
|
||||
**Arguments**:
|
||||
> - other: 另一条直线
|
||||
> - epsilon: 误差
|
||||
|
||||
**Return**: 是否近似相等
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def approx(self, other: 'Line3', epsilon: float=APPROX) -> bool:
|
||||
"""
|
||||
判断两条直线是否近似相等。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
epsilon: 误差
|
||||
Returns:
|
||||
是否近似相等
|
||||
"""
|
||||
return self.is_approx_parallel(other, epsilon) and (self.point - other.point).is_approx_parallel(self.direction, epsilon)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_angle(self, other: Line3) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**Description**: 计算直线和直线之间的夹角。
|
||||
|
||||
**Arguments**:
|
||||
> - other: 另一条直线
|
||||
|
||||
**Return**: 夹角弧度
|
||||
|
||||
**Raises**:
|
||||
> - TypeError 不支持的类型
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_angle(self, other: 'Line3') -> 'AnyAngle':
|
||||
"""
|
||||
计算直线和直线之间的夹角。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
Returns:
|
||||
夹角弧度
|
||||
Raises:
|
||||
TypeError: 不支持的类型
|
||||
"""
|
||||
return self.direction.cal_angle(other.direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_distance(self, other: Line3 | Point3) -> float`
|
||||
|
||||
|
||||
|
||||
**Description**: 计算直线和直线或点之间的距离。
|
||||
|
||||
**Arguments**:
|
||||
> - other: 平行直线或点
|
||||
|
||||
**Return**: 距离
|
||||
|
||||
**Raises**:
|
||||
> - TypeError 不支持的类型
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_distance(self, other: 'Line3 | Point3') -> float:
|
||||
"""
|
||||
计算直线和直线或点之间的距离。
|
||||
Args:
|
||||
other: 平行直线或点
|
||||
|
||||
Returns:
|
||||
距离
|
||||
Raises:
|
||||
TypeError: 不支持的类型
|
||||
"""
|
||||
if isinstance(other, Line3):
|
||||
if self == other:
|
||||
return 0
|
||||
elif self.is_parallel(other):
|
||||
return (other.point - self.point).cross(self.direction).length / self.direction.length
|
||||
elif not self.is_coplanar(other):
|
||||
return abs(self.direction.cross(other.direction) @ (self.point - other.point) / self.direction.cross(other.direction).length)
|
||||
else:
|
||||
return 0
|
||||
elif isinstance(other, Point3):
|
||||
return (other - self.point).cross(self.direction).length / self.direction.length
|
||||
else:
|
||||
raise TypeError('Unsupported type.')
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_intersection(self, other: Line3) -> Point3`
|
||||
|
||||
|
||||
|
||||
**Description**: 计算两条直线的交点。
|
||||
|
||||
**Arguments**:
|
||||
> - other: 另一条直线
|
||||
|
||||
**Return**: 交点
|
||||
|
||||
**Raises**:
|
||||
> - ValueError 直线平行
|
||||
> - ValueError 直线不共面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_intersection(self, other: 'Line3') -> 'Point3':
|
||||
"""
|
||||
计算两条直线的交点。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
Returns:
|
||||
交点
|
||||
Raises:
|
||||
ValueError: 直线平行
|
||||
ValueError: 直线不共面
|
||||
"""
|
||||
if self.is_parallel(other):
|
||||
raise ValueError('Lines are parallel and do not intersect.')
|
||||
if not self.is_coplanar(other):
|
||||
raise ValueError('Lines are not coplanar and do not intersect.')
|
||||
return self.point + self.direction.cross(other.direction) @ other.direction.cross(self.point - other.point) / self.direction.cross(other.direction).length ** 2 * self.direction
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_perpendicular(self, point: Point3) -> Line3`
|
||||
|
||||
|
||||
|
||||
**Description**: 计算直线经过指定点p的垂线。
|
||||
|
||||
**Arguments**:
|
||||
> - point: 指定点
|
||||
|
||||
**Return**: 垂线
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_perpendicular(self, point: 'Point3') -> 'Line3':
|
||||
"""
|
||||
计算直线经过指定点p的垂线。
|
||||
Args:
|
||||
point: 指定点
|
||||
Returns:
|
||||
垂线
|
||||
"""
|
||||
return Line3(point, self.direction.cross(point - self.point))
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `get_point(self, t: RealNumber) -> Point3`
|
||||
|
||||
|
||||
|
||||
**Description**: 获取直线上的点。同一条直线,但起始点和方向向量不同,则同一个t对应的点不同。
|
||||
|
||||
**Arguments**:
|
||||
> - t: 参数t
|
||||
|
||||
**Return**: 点
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def get_point(self, t: RealNumber) -> 'Point3':
|
||||
"""
|
||||
获取直线上的点。同一条直线,但起始点和方向向量不同,则同一个t对应的点不同。
|
||||
Args:
|
||||
t: 参数t
|
||||
Returns:
|
||||
点
|
||||
"""
|
||||
return self.point + t * self.direction
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `get_parametric_equations(self) -> tuple[OneSingleVarFunc, OneSingleVarFunc, OneSingleVarFunc]`
|
||||
|
||||
|
||||
|
||||
**Description**: 获取直线的参数方程。
|
||||
|
||||
**Return**: x(t), y(t), z(t)
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def get_parametric_equations(self) -> tuple[OneSingleVarFunc, OneSingleVarFunc, OneSingleVarFunc]:
|
||||
"""
|
||||
获取直线的参数方程。
|
||||
Returns:
|
||||
x(t), y(t), z(t)
|
||||
"""
|
||||
return (lambda t: self.point.x + self.direction.x * t, lambda t: self.point.y + self.direction.y * t, lambda t: self.point.z + self.direction.z * t)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_approx_parallel(self, other: Line3, epsilon: float = 1e-06) -> bool`
|
||||
|
||||
|
||||
|
||||
**Description**: 判断两条直线是否近似平行。
|
||||
|
||||
**Arguments**:
|
||||
> - other: 另一条直线
|
||||
> - epsilon: 误差
|
||||
|
||||
**Return**: 是否近似平行
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def is_approx_parallel(self, other: 'Line3', epsilon: float=1e-06) -> bool:
|
||||
"""
|
||||
判断两条直线是否近似平行。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
epsilon: 误差
|
||||
Returns:
|
||||
是否近似平行
|
||||
"""
|
||||
return self.direction.is_approx_parallel(other.direction, epsilon)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_parallel(self, other: Line3) -> bool`
|
||||
|
||||
|
||||
|
||||
**Description**: 判断两条直线是否平行。
|
||||
|
||||
**Arguments**:
|
||||
> - other: 另一条直线
|
||||
|
||||
**Return**: 是否平行
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def is_parallel(self, other: 'Line3') -> bool:
|
||||
"""
|
||||
判断两条直线是否平行。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
Returns:
|
||||
是否平行
|
||||
"""
|
||||
return self.direction.is_parallel(other.direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_collinear(self, other: Line3) -> bool`
|
||||
|
||||
|
||||
|
||||
**Description**: 判断两条直线是否共线。
|
||||
|
||||
**Arguments**:
|
||||
> - other: 另一条直线
|
||||
|
||||
**Return**: 是否共线
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def is_collinear(self, other: 'Line3') -> bool:
|
||||
"""
|
||||
判断两条直线是否共线。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
Returns:
|
||||
是否共线
|
||||
"""
|
||||
return self.is_parallel(other) and (self.point - other.point).is_parallel(self.direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_point_on(self, point: Point3) -> bool`
|
||||
|
||||
|
||||
|
||||
**Description**: 判断点是否在直线上。
|
||||
|
||||
**Arguments**:
|
||||
> - point: 点
|
||||
|
||||
**Return**: 是否在直线上
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def is_point_on(self, point: 'Point3') -> bool:
|
||||
"""
|
||||
判断点是否在直线上。
|
||||
Args:
|
||||
point: 点
|
||||
Returns:
|
||||
是否在直线上
|
||||
"""
|
||||
return (point - self.point).is_parallel(self.direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_coplanar(self, other: Line3) -> bool`
|
||||
|
||||
|
||||
|
||||
**Description**: 判断两条直线是否共面。
|
||||
充要条件:两直线方向向量的叉乘与两直线上任意一点的向量的点积为0。
|
||||
|
||||
**Arguments**:
|
||||
> - other: 另一条直线
|
||||
|
||||
**Return**: 是否共面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def is_coplanar(self, other: 'Line3') -> bool:
|
||||
"""
|
||||
判断两条直线是否共面。
|
||||
充要条件:两直线方向向量的叉乘与两直线上任意一点的向量的点积为0。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
Returns:
|
||||
是否共面
|
||||
"""
|
||||
return self.direction.cross(other.direction) @ (self.point - other.point) == 0
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `simplify(self)`
|
||||
|
||||
|
||||
|
||||
**Description**: 简化直线方程,等价相等。
|
||||
自体简化,不返回值。
|
||||
|
||||
按照可行性一次对x y z 化 0 处理,并对向量单位化
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def simplify(self):
|
||||
"""
|
||||
简化直线方程,等价相等。
|
||||
自体简化,不返回值。
|
||||
|
||||
按照可行性一次对x y z 化 0 处理,并对向量单位化
|
||||
"""
|
||||
self.direction.normalize()
|
||||
if self.direction.x == 0:
|
||||
self.point.x = 0
|
||||
if self.direction.y == 0:
|
||||
self.point.y = 0
|
||||
if self.direction.z == 0:
|
||||
self.point.z = 0
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@classmethod`
|
||||
### *method* `from_two_points(cls, p1: Point3, p2: Point3) -> Line3`
|
||||
|
||||
|
||||
|
||||
**Description**: 工厂函数 由两点构造直线。
|
||||
|
||||
**Arguments**:
|
||||
> - p1: 点1
|
||||
> - p2: 点2
|
||||
|
||||
**Return**: 直线
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@classmethod
|
||||
def from_two_points(cls, p1: 'Point3', p2: 'Point3') -> 'Line3':
|
||||
"""
|
||||
工厂函数 由两点构造直线。
|
||||
Args:
|
||||
p1: 点1
|
||||
p2: 点2
|
||||
Returns:
|
||||
直线
|
||||
"""
|
||||
direction = p2 - p1
|
||||
return cls(p1, direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__and__(self, other: Line3) -> Line3 | Point3 | None`
|
||||
|
||||
|
||||
|
||||
**Description**: 计算两条直线点集合的交集。重合线返回自身,平行线返回None,交线返回交点。
|
||||
|
||||
**Arguments**:
|
||||
> - other: 另一条直线
|
||||
|
||||
**Return**: 交点
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __and__(self, other: 'Line3') -> 'Line3 | Point3 | None':
|
||||
"""
|
||||
计算两条直线点集合的交集。重合线返回自身,平行线返回None,交线返回交点。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
Returns:
|
||||
交点
|
||||
"""
|
||||
if self.is_collinear(other):
|
||||
return self
|
||||
elif self.is_parallel(other) or not self.is_coplanar(other):
|
||||
return None
|
||||
else:
|
||||
return self.cal_intersection(other)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__eq__(self, other) -> bool`
|
||||
|
||||
|
||||
|
||||
**Description**: 判断两条直线是否等价。
|
||||
|
||||
v1 // v2 ∧ (p1 - p2) // v1
|
||||
|
||||
**Arguments**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __eq__(self, other) -> bool:
|
||||
"""
|
||||
判断两条直线是否等价。
|
||||
|
||||
v1 // v2 ∧ (p1 - p2) // v1
|
||||
Args:
|
||||
other:
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
return self.direction.is_parallel(other.direction) and (self.point - other.point).is_parallel(self.direction)
|
||||
```
|
||||
</details>
|
||||
|
@ -1,63 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.mp_math_typing
|
||||
---
|
||||
### ***var*** `RealNumber = int | float`
|
||||
|
||||
- **Type**: `TypeAlias`
|
||||
|
||||
### ***var*** `Number = RealNumber | complex`
|
||||
|
||||
- **Type**: `TypeAlias`
|
||||
|
||||
### ***var*** `Var = SingleVar | ArrayVar`
|
||||
|
||||
- **Type**: `TypeAlias`
|
||||
|
||||
### ***var*** `OneSingleVarFunc = Callable[[SingleVar], SingleVar]`
|
||||
|
||||
- **Type**: `TypeAlias`
|
||||
|
||||
### ***var*** `OneArrayFunc = Callable[[ArrayVar], ArrayVar]`
|
||||
|
||||
- **Type**: `TypeAlias`
|
||||
|
||||
### ***var*** `OneVarFunc = OneSingleVarFunc | OneArrayFunc`
|
||||
|
||||
- **Type**: `TypeAlias`
|
||||
|
||||
### ***var*** `TwoSingleVarsFunc = Callable[[SingleVar, SingleVar], SingleVar]`
|
||||
|
||||
- **Type**: `TypeAlias`
|
||||
|
||||
### ***var*** `TwoArraysFunc = Callable[[ArrayVar, ArrayVar], ArrayVar]`
|
||||
|
||||
- **Type**: `TypeAlias`
|
||||
|
||||
### ***var*** `TwoVarsFunc = TwoSingleVarsFunc | TwoArraysFunc`
|
||||
|
||||
- **Type**: `TypeAlias`
|
||||
|
||||
### ***var*** `ThreeSingleVarsFunc = Callable[[SingleVar, SingleVar, SingleVar], SingleVar]`
|
||||
|
||||
- **Type**: `TypeAlias`
|
||||
|
||||
### ***var*** `ThreeArraysFunc = Callable[[ArrayVar, ArrayVar, ArrayVar], ArrayVar]`
|
||||
|
||||
- **Type**: `TypeAlias`
|
||||
|
||||
### ***var*** `ThreeVarsFunc = ThreeSingleVarsFunc | ThreeArraysFunc`
|
||||
|
||||
- **Type**: `TypeAlias`
|
||||
|
||||
### ***var*** `MultiSingleVarsFunc = Callable[..., SingleVar]`
|
||||
|
||||
- **Type**: `TypeAlias`
|
||||
|
||||
### ***var*** `MultiArraysFunc = Callable[..., ArrayVar]`
|
||||
|
||||
- **Type**: `TypeAlias`
|
||||
|
||||
### ***var*** `MultiVarsFunc = MultiSingleVarsFunc | MultiArraysFunc`
|
||||
|
||||
- **Type**: `TypeAlias`
|
||||
|
@ -1,542 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.plane
|
||||
---
|
||||
### **class** `Plane3`
|
||||
### *method* `__init__(self, a: float, b: float, c: float, d: float)`
|
||||
|
||||
|
||||
|
||||
**Description**: 平面方程:ax + by + cz + d = 0
|
||||
|
||||
**Arguments**:
|
||||
> - a: x系数
|
||||
> - b: y系数
|
||||
> - c: z系数
|
||||
> - d: 常数项
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, a: float, b: float, c: float, d: float):
|
||||
"""
|
||||
平面方程:ax + by + cz + d = 0
|
||||
Args:
|
||||
a: x系数
|
||||
b: y系数
|
||||
c: z系数
|
||||
d: 常数项
|
||||
"""
|
||||
self.a = a
|
||||
self.b = b
|
||||
self.c = c
|
||||
self.d = d
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `approx(self, other: Plane3) -> bool`
|
||||
|
||||
|
||||
|
||||
**Description**: 判断两个平面是否近似相等。
|
||||
|
||||
**Arguments**:
|
||||
> - other: 另一个平面
|
||||
|
||||
**Return**: 是否近似相等
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def approx(self, other: 'Plane3') -> bool:
|
||||
"""
|
||||
判断两个平面是否近似相等。
|
||||
Args:
|
||||
other: 另一个平面
|
||||
Returns:
|
||||
是否近似相等
|
||||
"""
|
||||
if self.a != 0:
|
||||
k = other.a / self.a
|
||||
return approx(other.b, self.b * k) and approx(other.c, self.c * k) and approx(other.d, self.d * k)
|
||||
elif self.b != 0:
|
||||
k = other.b / self.b
|
||||
return approx(other.a, self.a * k) and approx(other.c, self.c * k) and approx(other.d, self.d * k)
|
||||
elif self.c != 0:
|
||||
k = other.c / self.c
|
||||
return approx(other.a, self.a * k) and approx(other.b, self.b * k) and approx(other.d, self.d * k)
|
||||
else:
|
||||
return False
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_angle(self, other: Line3 | Plane3) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**Description**: 计算平面与平面之间的夹角。
|
||||
|
||||
**Arguments**:
|
||||
> - other: 另一个平面
|
||||
|
||||
**Return**: 夹角弧度
|
||||
|
||||
**Raises**:
|
||||
> - TypeError 不支持的类型
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_angle(self, other: 'Line3 | Plane3') -> 'AnyAngle':
|
||||
"""
|
||||
计算平面与平面之间的夹角。
|
||||
Args:
|
||||
other: 另一个平面
|
||||
Returns:
|
||||
夹角弧度
|
||||
Raises:
|
||||
TypeError: 不支持的类型
|
||||
"""
|
||||
if isinstance(other, Line3):
|
||||
return self.normal.cal_angle(other.direction).complementary
|
||||
elif isinstance(other, Plane3):
|
||||
return AnyAngle(math.acos(self.normal @ other.normal / (self.normal.length * other.normal.length)), is_radian=True)
|
||||
else:
|
||||
raise TypeError(f'Unsupported type: {type(other)}')
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_distance(self, other: Plane3 | Point3) -> float`
|
||||
|
||||
|
||||
|
||||
**Description**: 计算平面与平面或点之间的距离。
|
||||
|
||||
**Arguments**:
|
||||
> - other: 另一个平面或点
|
||||
|
||||
**Return**: 距离
|
||||
|
||||
**Raises**:
|
||||
> - TypeError 不支持的类型
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_distance(self, other: 'Plane3 | Point3') -> float:
|
||||
"""
|
||||
计算平面与平面或点之间的距离。
|
||||
Args:
|
||||
other: 另一个平面或点
|
||||
Returns:
|
||||
距离
|
||||
Raises:
|
||||
TypeError: 不支持的类型
|
||||
"""
|
||||
if isinstance(other, Plane3):
|
||||
return 0
|
||||
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:
|
||||
raise TypeError(f'Unsupported type: {type(other)}')
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_intersection_line3(self, other: Plane3) -> Line3`
|
||||
|
||||
|
||||
|
||||
**Description**: 计算两平面的交线。
|
||||
|
||||
**Arguments**:
|
||||
> - other: 另一个平面
|
||||
|
||||
**Return**: 两平面的交线
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_intersection_line3(self, other: 'Plane3') -> 'Line3':
|
||||
"""
|
||||
计算两平面的交线。
|
||||
Args:
|
||||
other: 另一个平面
|
||||
Returns:
|
||||
两平面的交线
|
||||
Raises:
|
||||
"""
|
||||
if self.normal.is_parallel(other.normal):
|
||||
raise ValueError('Planes are parallel and have no intersection.')
|
||||
direction = self.normal.cross(other.normal)
|
||||
x, y, z = (0, 0, 0)
|
||||
if self.a != 0 and other.a != 0:
|
||||
A = np.array([[self.b, self.c], [other.b, other.c]])
|
||||
B = np.array([-self.d, -other.d])
|
||||
y, z = np.linalg.solve(A, B)
|
||||
elif self.b != 0 and other.b != 0:
|
||||
A = np.array([[self.a, self.c], [other.a, other.c]])
|
||||
B = np.array([-self.d, -other.d])
|
||||
x, z = np.linalg.solve(A, B)
|
||||
elif self.c != 0 and other.c != 0:
|
||||
A = np.array([[self.a, self.b], [other.a, other.b]])
|
||||
B = np.array([-self.d, -other.d])
|
||||
x, y = np.linalg.solve(A, B)
|
||||
return Line3(Point3(x, y, z), direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_intersection_point3(self, other: Line3) -> Point3`
|
||||
|
||||
|
||||
|
||||
**Description**: 计算平面与直线的交点。
|
||||
|
||||
**Arguments**:
|
||||
> - other: 不与平面平行或在平面上的直线
|
||||
|
||||
**Return**: 交点
|
||||
|
||||
**Raises**:
|
||||
> - ValueError 平面与直线平行或重合
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_intersection_point3(self, other: 'Line3') -> 'Point3':
|
||||
"""
|
||||
计算平面与直线的交点。
|
||||
Args:
|
||||
other: 不与平面平行或在平面上的直线
|
||||
Returns:
|
||||
交点
|
||||
Raises:
|
||||
ValueError: 平面与直线平行或重合
|
||||
"""
|
||||
if self.normal @ other.direction == 0:
|
||||
raise ValueError('The plane and the line are parallel or coincident.')
|
||||
x, y, z = other.get_parametric_equations()
|
||||
t = -(self.a * other.point.x + self.b * other.point.y + self.c * other.point.z + self.d) / (self.a * other.direction.x + self.b * other.direction.y + self.c * other.direction.z)
|
||||
return Point3(x(t), y(t), z(t))
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_parallel_plane3(self, point: Point3) -> Plane3`
|
||||
|
||||
|
||||
|
||||
**Description**: 计算平行于该平面且过指定点的平面。
|
||||
|
||||
**Arguments**:
|
||||
> - point: 指定点
|
||||
|
||||
**Return**: 所求平面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_parallel_plane3(self, point: 'Point3') -> 'Plane3':
|
||||
"""
|
||||
计算平行于该平面且过指定点的平面。
|
||||
Args:
|
||||
point: 指定点
|
||||
Returns:
|
||||
所求平面
|
||||
"""
|
||||
return Plane3.from_point_and_normal(point, self.normal)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_parallel(self, other: Plane3) -> bool`
|
||||
|
||||
|
||||
|
||||
**Description**: 判断两个平面是否平行。
|
||||
|
||||
**Arguments**:
|
||||
> - other: 另一个平面
|
||||
|
||||
**Return**: 是否平行
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def is_parallel(self, other: 'Plane3') -> bool:
|
||||
"""
|
||||
判断两个平面是否平行。
|
||||
Args:
|
||||
other: 另一个平面
|
||||
Returns:
|
||||
是否平行
|
||||
"""
|
||||
return self.normal.is_parallel(other.normal)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `normal(self) -> Vector3`
|
||||
|
||||
|
||||
|
||||
**Description**: 平面的法向量。
|
||||
|
||||
**Return**: 法向量
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def normal(self) -> 'Vector3':
|
||||
"""
|
||||
平面的法向量。
|
||||
Returns:
|
||||
法向量
|
||||
"""
|
||||
return Vector3(self.a, self.b, self.c)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@classmethod`
|
||||
### *method* `from_point_and_normal(cls, point: Point3, normal: Vector3) -> Plane3`
|
||||
|
||||
|
||||
|
||||
**Description**: 工厂函数 由点和法向量构造平面(点法式构造)。
|
||||
|
||||
**Arguments**:
|
||||
> - point: 平面上的一点
|
||||
> - normal: 法向量
|
||||
|
||||
**Return**: 平面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@classmethod
|
||||
def from_point_and_normal(cls, point: 'Point3', normal: 'Vector3') -> 'Plane3':
|
||||
"""
|
||||
工厂函数 由点和法向量构造平面(点法式构造)。
|
||||
Args:
|
||||
point: 平面上的一点
|
||||
normal: 法向量
|
||||
Returns:
|
||||
平面
|
||||
"""
|
||||
a, b, c = (normal.x, normal.y, normal.z)
|
||||
d = -a * point.x - b * point.y - c * point.z
|
||||
return cls(a, b, c, d)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@classmethod`
|
||||
### *method* `from_three_points(cls, p1: Point3, p2: Point3, p3: Point3) -> Plane3`
|
||||
|
||||
|
||||
|
||||
**Description**: 工厂函数 由三点构造平面。
|
||||
|
||||
**Arguments**:
|
||||
> - p1: 点1
|
||||
> - p2: 点2
|
||||
> - p3: 点3
|
||||
|
||||
**Return**: 平面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@classmethod
|
||||
def from_three_points(cls, p1: 'Point3', p2: 'Point3', p3: 'Point3') -> 'Plane3':
|
||||
"""
|
||||
工厂函数 由三点构造平面。
|
||||
Args:
|
||||
p1: 点1
|
||||
p2: 点2
|
||||
p3: 点3
|
||||
Returns:
|
||||
平面
|
||||
"""
|
||||
v1 = p2 - p1
|
||||
v2 = p3 - p1
|
||||
normal = v1.cross(v2)
|
||||
return cls.from_point_and_normal(p1, normal)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@classmethod`
|
||||
### *method* `from_two_lines(cls, l1: Line3, l2: Line3) -> Plane3`
|
||||
|
||||
|
||||
|
||||
**Description**: 工厂函数 由两直线构造平面。
|
||||
|
||||
**Arguments**:
|
||||
> - l1: 直线1
|
||||
> - l2: 直线2
|
||||
|
||||
**Return**: 平面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@classmethod
|
||||
def from_two_lines(cls, l1: 'Line3', l2: 'Line3') -> 'Plane3':
|
||||
"""
|
||||
工厂函数 由两直线构造平面。
|
||||
Args:
|
||||
l1: 直线1
|
||||
l2: 直线2
|
||||
Returns:
|
||||
平面
|
||||
"""
|
||||
v1 = l1.direction
|
||||
v2 = l2.point - l1.point
|
||||
if v2 == zero_vector3:
|
||||
v2 = l2.get_point(1) - l1.point
|
||||
return cls.from_point_and_normal(l1.point, v1.cross(v2))
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@classmethod`
|
||||
### *method* `from_point_and_line(cls, point: Point3, line: Line3) -> Plane3`
|
||||
|
||||
|
||||
|
||||
**Description**: 工厂函数 由点和直线构造平面。
|
||||
|
||||
**Arguments**:
|
||||
> - point: 面上一点
|
||||
> - line: 面上直线,不包含点
|
||||
|
||||
**Return**: 平面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@classmethod
|
||||
def from_point_and_line(cls, point: 'Point3', line: 'Line3') -> 'Plane3':
|
||||
"""
|
||||
工厂函数 由点和直线构造平面。
|
||||
Args:
|
||||
point: 面上一点
|
||||
line: 面上直线,不包含点
|
||||
Returns:
|
||||
平面
|
||||
"""
|
||||
return cls.from_point_and_normal(point, line.direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `__and__(self, other: Line3) -> Point3 | None`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __and__(self, other: 'Line3') -> 'Point3 | None':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `__and__(self, other: Plane3) -> Line3 | None`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __and__(self, other: 'Plane3') -> 'Line3 | None':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__and__(self, other)`
|
||||
|
||||
|
||||
|
||||
**Description**: 取两平面的交集(人话:交线)
|
||||
|
||||
**Arguments**:
|
||||
> - other:
|
||||
|
||||
**Return**: 不平行平面的交线,平面平行返回None
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __and__(self, other):
|
||||
"""
|
||||
取两平面的交集(人话:交线)
|
||||
Args:
|
||||
other:
|
||||
Returns:
|
||||
不平行平面的交线,平面平行返回None
|
||||
"""
|
||||
if isinstance(other, Plane3):
|
||||
if self.normal.is_parallel(other.normal):
|
||||
return None
|
||||
return self.cal_intersection_line3(other)
|
||||
elif isinstance(other, Line3):
|
||||
if self.normal @ other.direction == 0:
|
||||
return None
|
||||
return self.cal_intersection_point3(other)
|
||||
else:
|
||||
raise TypeError(f"unsupported operand type(s) for &: 'Plane3' and '{type(other)}'")
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__eq__(self, other) -> bool`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __eq__(self, other) -> bool:
|
||||
return self.approx(other)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__rand__(self, other: Line3) -> Point3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __rand__(self, other: 'Line3') -> 'Point3':
|
||||
return self.cal_intersection_point3(other)
|
||||
```
|
||||
</details>
|
||||
|
@ -1,176 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.point
|
||||
---
|
||||
### **class** `Point3`
|
||||
### *method* `__init__(self, x: float, y: float, z: float)`
|
||||
|
||||
|
||||
|
||||
**Description**: 笛卡尔坐标系中的点。
|
||||
|
||||
**Arguments**:
|
||||
> - x: x 坐标
|
||||
> - y: y 坐标
|
||||
> - z: z 坐标
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```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>
|
||||
|
||||
### *method* `approx(self, other: Point3, epsilon: float = APPROX) -> bool`
|
||||
|
||||
|
||||
|
||||
**Description**: 判断两个点是否近似相等。
|
||||
|
||||
**Arguments**:
|
||||
> - other:
|
||||
> - epsilon:
|
||||
|
||||
**Return**: 是否近似相等
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```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>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self + other: Vector3 => Point3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __add__(self, other: 'Vector3') -> 'Point3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self + other: Point3 => Point3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __add__(self, other: 'Point3') -> 'Point3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self + other`
|
||||
|
||||
|
||||
|
||||
**Description**: P + V -> P
|
||||
P + P -> P
|
||||
|
||||
**Arguments**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```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>
|
||||
|
||||
### *method* `__eq__(self, other)`
|
||||
|
||||
|
||||
|
||||
**Description**: 判断两个点是否相等。
|
||||
|
||||
**Arguments**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```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>
|
||||
|
||||
### *method* `self - other: Point3 => Vector3`
|
||||
|
||||
|
||||
|
||||
**Description**: P - P -> V
|
||||
|
||||
P - V -> P 已在 :class:`Vector3` 中实现
|
||||
|
||||
**Arguments**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```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>
|
||||
|
@ -1,34 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.segment
|
||||
---
|
||||
### **class** `Segment3`
|
||||
### *method* `__init__(self, p1: Point3, p2: Point3)`
|
||||
|
||||
|
||||
|
||||
**Description**: 三维空间中的线段。
|
||||
:param p1:
|
||||
:param p2:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, p1: 'Point3', p2: 'Point3'):
|
||||
"""
|
||||
三维空间中的线段。
|
||||
:param p1:
|
||||
:param p2:
|
||||
"""
|
||||
self.p1 = p1
|
||||
self.p2 = p2
|
||||
'方向向量'
|
||||
self.direction = self.p2 - self.p1
|
||||
'长度'
|
||||
self.length = self.direction.length
|
||||
'中心点'
|
||||
self.midpoint = Point3((self.p1.x + self.p2.x) / 2, (self.p1.y + self.p2.y) / 2, (self.p1.z + self.p2.z) / 2)
|
||||
```
|
||||
</details>
|
||||
|
@ -1,200 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.utils
|
||||
---
|
||||
### *func* `clamp() -> float`
|
||||
|
||||
|
||||
|
||||
**Description**: 区间限定函数
|
||||
|
||||
**Arguments**:
|
||||
> - x: 待限定的值
|
||||
> - min_: 最小值
|
||||
> - max_: 最大值
|
||||
|
||||
**Return**: 限制后的值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def clamp(x: float, min_: float, max_: float) -> float:
|
||||
"""
|
||||
区间限定函数
|
||||
Args:
|
||||
x: 待限定的值
|
||||
min_: 最小值
|
||||
max_: 最大值
|
||||
|
||||
Returns:
|
||||
限制后的值
|
||||
"""
|
||||
return max(min(x, max_), min_)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *func* `approx(x: float = 0.0, y: float = APPROX) -> bool`
|
||||
|
||||
|
||||
|
||||
**Description**: 判断两个数是否近似相等。或包装一个实数,用于判断是否近似于0。
|
||||
|
||||
**Arguments**:
|
||||
> - x: 数1
|
||||
> - y: 数2
|
||||
> - epsilon: 误差
|
||||
|
||||
**Return**: 是否近似相等
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def approx(x: float, y: float=0.0, epsilon: float=APPROX) -> bool:
|
||||
"""
|
||||
判断两个数是否近似相等。或包装一个实数,用于判断是否近似于0。
|
||||
Args:
|
||||
x: 数1
|
||||
y: 数2
|
||||
epsilon: 误差
|
||||
Returns:
|
||||
是否近似相等
|
||||
"""
|
||||
return abs(x - y) < epsilon
|
||||
```
|
||||
</details>
|
||||
|
||||
### *func* `sign(x: float = False) -> str`
|
||||
|
||||
|
||||
|
||||
**Description**: 获取数的符号。
|
||||
|
||||
**Arguments**:
|
||||
> - x: 数
|
||||
> - only_neg: 是否只返回负数的符号
|
||||
|
||||
**Return**: 符号 + - ""
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def sign(x: float, only_neg: bool=False) -> str:
|
||||
"""获取数的符号。
|
||||
Args:
|
||||
x: 数
|
||||
only_neg: 是否只返回负数的符号
|
||||
Returns:
|
||||
符号 + - ""
|
||||
"""
|
||||
if x > 0:
|
||||
return '+' if not only_neg else ''
|
||||
elif x < 0:
|
||||
return '-'
|
||||
else:
|
||||
return ''
|
||||
```
|
||||
</details>
|
||||
|
||||
### *func* `sign_format(x: float = False) -> str`
|
||||
|
||||
|
||||
|
||||
**Description**: 格式化符号数
|
||||
-1 -> -1
|
||||
1 -> +1
|
||||
0 -> ""
|
||||
|
||||
**Arguments**:
|
||||
> - x: 数
|
||||
> - only_neg: 是否只返回负数的符号
|
||||
|
||||
**Return**: 符号 + - ""
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def sign_format(x: float, only_neg: bool=False) -> str:
|
||||
"""格式化符号数
|
||||
-1 -> -1
|
||||
1 -> +1
|
||||
0 -> ""
|
||||
Args:
|
||||
x: 数
|
||||
only_neg: 是否只返回负数的符号
|
||||
Returns:
|
||||
符号 + - ""
|
||||
"""
|
||||
if x > 0:
|
||||
return f'+{x}' if not only_neg else f'{x}'
|
||||
elif x < 0:
|
||||
return f'-{abs(x)}'
|
||||
else:
|
||||
return ''
|
||||
```
|
||||
</details>
|
||||
|
||||
### **class** `Approx`
|
||||
### *method* `__init__(self, value: RealNumber)`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, value: RealNumber):
|
||||
self.value = value
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__eq__(self, other)`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __eq__(self, other):
|
||||
if isinstance(self.value, (float, int)):
|
||||
if isinstance(other, (float, int)):
|
||||
return abs(self.value - other) < APPROX
|
||||
else:
|
||||
self.raise_type_error(other)
|
||||
elif isinstance(self.value, Vector3):
|
||||
if isinstance(other, (Vector3, Point3, Plane3, Line3)):
|
||||
return all([approx(self.value.x, other.x), approx(self.value.y, other.y), approx(self.value.z, other.z)])
|
||||
else:
|
||||
self.raise_type_error(other)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `raise_type_error(self, other)`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def raise_type_error(self, other):
|
||||
raise TypeError(f'Unsupported type: {type(self.value)} and {type(other)}')
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__ne__(self, other)`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
```
|
||||
</details>
|
||||
|
@ -1,656 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.vector
|
||||
---
|
||||
### **class** `Vector3`
|
||||
### *method* `__init__(self, x: float, y: float, z: float)`
|
||||
|
||||
|
||||
|
||||
**Description**: 3维向量
|
||||
|
||||
**Arguments**:
|
||||
> - x: x轴分量
|
||||
> - y: y轴分量
|
||||
> - z: z轴分量
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, x: float, y: float, z: float):
|
||||
"""
|
||||
3维向量
|
||||
Args:
|
||||
x: x轴分量
|
||||
y: y轴分量
|
||||
z: z轴分量
|
||||
"""
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.z = z
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `approx(self, other: Vector3, epsilon: float = APPROX) -> bool`
|
||||
|
||||
|
||||
|
||||
**Description**: 判断两个向量是否近似相等。
|
||||
|
||||
**Arguments**:
|
||||
> - other:
|
||||
> - epsilon:
|
||||
|
||||
**Return**: 是否近似相等
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def approx(self, other: 'Vector3', 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>
|
||||
|
||||
### *method* `cal_angle(self, other: Vector3) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**Description**: 计算两个向量之间的夹角。
|
||||
|
||||
**Arguments**:
|
||||
> - other: 另一个向量
|
||||
|
||||
**Return**: 夹角
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_angle(self, other: 'Vector3') -> 'AnyAngle':
|
||||
"""
|
||||
计算两个向量之间的夹角。
|
||||
Args:
|
||||
other: 另一个向量
|
||||
Returns:
|
||||
夹角
|
||||
"""
|
||||
return AnyAngle(math.acos(self @ other / (self.length * other.length)), is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cross(self, other: Vector3) -> Vector3`
|
||||
|
||||
|
||||
|
||||
**Description**: 向量积 叉乘:v1 cross v2 -> v3
|
||||
|
||||
叉乘为0,则两向量平行。
|
||||
其余结果的模为平行四边形的面积。
|
||||
|
||||
|
||||
**Arguments**:
|
||||
> - other:
|
||||
|
||||
**Return**: 行列式的结果
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def cross(self, other: 'Vector3') -> 'Vector3':
|
||||
"""
|
||||
向量积 叉乘:v1 cross v2 -> v3
|
||||
|
||||
叉乘为0,则两向量平行。
|
||||
其余结果的模为平行四边形的面积。
|
||||
|
||||
返回如下行列式的结果:
|
||||
|
||||
``i j k``
|
||||
|
||||
``x1 y1 z1``
|
||||
|
||||
``x2 y2 z2``
|
||||
|
||||
Args:
|
||||
other:
|
||||
Returns:
|
||||
行列式的结果
|
||||
"""
|
||||
return Vector3(self.y * other.z - self.z * other.y, self.z * other.x - self.x * other.z, self.x * other.y - self.y * other.x)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_approx_parallel(self, other: Vector3, epsilon: float = APPROX) -> bool`
|
||||
|
||||
|
||||
|
||||
**Description**: 判断两个向量是否近似平行。
|
||||
|
||||
**Arguments**:
|
||||
> - other: 另一个向量
|
||||
> - epsilon: 允许的误差
|
||||
|
||||
**Return**: 是否近似平行
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def is_approx_parallel(self, other: 'Vector3', epsilon: float=APPROX) -> bool:
|
||||
"""
|
||||
判断两个向量是否近似平行。
|
||||
Args:
|
||||
other: 另一个向量
|
||||
epsilon: 允许的误差
|
||||
Returns:
|
||||
是否近似平行
|
||||
"""
|
||||
return self.cross(other).length < epsilon
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_parallel(self, other: Vector3) -> bool`
|
||||
|
||||
|
||||
|
||||
**Description**: 判断两个向量是否平行。
|
||||
|
||||
**Arguments**:
|
||||
> - other: 另一个向量
|
||||
|
||||
**Return**: 是否平行
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def is_parallel(self, other: 'Vector3') -> bool:
|
||||
"""
|
||||
判断两个向量是否平行。
|
||||
Args:
|
||||
other: 另一个向量
|
||||
Returns:
|
||||
是否平行
|
||||
"""
|
||||
return self.cross(other).approx(zero_vector3)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `normalize(self)`
|
||||
|
||||
|
||||
|
||||
**Description**: 将向量归一化。
|
||||
|
||||
自体归一化,不返回值。
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def normalize(self):
|
||||
"""
|
||||
将向量归一化。
|
||||
|
||||
自体归一化,不返回值。
|
||||
"""
|
||||
length = self.length
|
||||
self.x /= length
|
||||
self.y /= length
|
||||
self.z /= length
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `np_array(self) -> np.ndarray`
|
||||
|
||||
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def np_array(self) -> 'np.ndarray':
|
||||
"""
|
||||
返回numpy数组
|
||||
Returns:
|
||||
"""
|
||||
return np.array([self.x, self.y, self.z])
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `length(self) -> float`
|
||||
|
||||
|
||||
|
||||
**Description**: 向量的模。
|
||||
|
||||
**Return**: 模
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def length(self) -> float:
|
||||
"""
|
||||
向量的模。
|
||||
Returns:
|
||||
模
|
||||
"""
|
||||
return math.sqrt(self.x ** 2 + self.y ** 2 + self.z ** 2)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `unit(self) -> Vector3`
|
||||
|
||||
|
||||
|
||||
**Description**: 获取该向量的单位向量。
|
||||
|
||||
**Return**: 单位向量
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def unit(self) -> 'Vector3':
|
||||
"""
|
||||
获取该向量的单位向量。
|
||||
Returns:
|
||||
单位向量
|
||||
"""
|
||||
return self / self.length
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__abs__(self)`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __abs__(self):
|
||||
return self.length
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self + other: Vector3 => Vector3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __add__(self, other: 'Vector3') -> 'Vector3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self + other: Point3 => Point3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __add__(self, other: 'Point3') -> 'Point3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self + other`
|
||||
|
||||
|
||||
|
||||
**Description**: V + P -> P
|
||||
|
||||
V + V -> V
|
||||
|
||||
**Arguments**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __add__(self, other):
|
||||
"""
|
||||
V + P -> P
|
||||
|
||||
V + V -> V
|
||||
Args:
|
||||
other:
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if isinstance(other, Vector3):
|
||||
return Vector3(self.x + other.x, self.y + other.y, self.z + other.z)
|
||||
elif isinstance(other, Point3):
|
||||
return Point3(self.x + other.x, self.y + other.y, self.z + other.z)
|
||||
else:
|
||||
raise TypeError(f"unsupported operand type(s) for +: 'Vector3' and '{type(other)}'")
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__eq__(self, other)`
|
||||
|
||||
|
||||
|
||||
**Description**: 判断两个向量是否相等。
|
||||
|
||||
**Arguments**:
|
||||
> - other:
|
||||
|
||||
**Return**: 是否相等
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```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>
|
||||
|
||||
### *method* `self + other: Point3 => Point3`
|
||||
|
||||
|
||||
|
||||
**Description**: P + V -> P
|
||||
|
||||
别去点那边实现了。
|
||||
:param other:
|
||||
:return:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __radd__(self, other: 'Point3') -> 'Point3':
|
||||
"""
|
||||
P + V -> P
|
||||
|
||||
别去点那边实现了。
|
||||
:param other:
|
||||
:return:
|
||||
"""
|
||||
return Point3(self.x + other.x, self.y + other.y, self.z + other.z)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self - other: Vector3 => Vector3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __sub__(self, other: 'Vector3') -> 'Vector3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self - other: Point3 => Point3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __sub__(self, other: 'Point3') -> 'Point3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self - other`
|
||||
|
||||
|
||||
|
||||
**Description**: V - P -> P
|
||||
|
||||
V - V -> V
|
||||
|
||||
**Arguments**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __sub__(self, other):
|
||||
"""
|
||||
V - P -> P
|
||||
|
||||
V - V -> V
|
||||
Args:
|
||||
other:
|
||||
Returns:
|
||||
"""
|
||||
if isinstance(other, Vector3):
|
||||
return Vector3(self.x - other.x, self.y - other.y, self.z - other.z)
|
||||
elif isinstance(other, Point3):
|
||||
return Point3(self.x - other.x, self.y - other.y, self.z - other.z)
|
||||
else:
|
||||
raise TypeError(f'unsupported operand type(s) for -: "Vector3" and "{type(other)}"')
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self - other: Point3`
|
||||
|
||||
|
||||
|
||||
**Description**: P - V -> P
|
||||
|
||||
**Arguments**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __rsub__(self, other: 'Point3'):
|
||||
"""
|
||||
P - V -> P
|
||||
Args:
|
||||
other:
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if isinstance(other, Point3):
|
||||
return Point3(other.x - self.x, other.y - self.y, other.z - self.z)
|
||||
else:
|
||||
raise TypeError(f"unsupported operand type(s) for -: '{type(other)}' and 'Vector3'")
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self * other: Vector3 => Vector3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __mul__(self, other: 'Vector3') -> 'Vector3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self * other: RealNumber => Vector3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __mul__(self, other: RealNumber) -> 'Vector3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self * other: int | float | Vector3 => Vector3`
|
||||
|
||||
|
||||
|
||||
**Description**: 数组运算 非点乘。点乘使用@,叉乘使用cross。
|
||||
|
||||
**Arguments**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __mul__(self, other: 'int | float | Vector3') -> 'Vector3':
|
||||
"""
|
||||
数组运算 非点乘。点乘使用@,叉乘使用cross。
|
||||
Args:
|
||||
other:
|
||||
|
||||
Returns:
|
||||
"""
|
||||
if isinstance(other, Vector3):
|
||||
return Vector3(self.x * other.x, self.y * other.y, self.z * other.z)
|
||||
elif isinstance(other, (float, int)):
|
||||
return Vector3(self.x * other, self.y * other, self.z * other)
|
||||
else:
|
||||
raise TypeError(f"unsupported operand type(s) for *: 'Vector3' and '{type(other)}'")
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self * other: RealNumber => Vector3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __rmul__(self, other: 'RealNumber') -> 'Vector3':
|
||||
return self.__mul__(other)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self @ other: Vector3 => RealNumber`
|
||||
|
||||
|
||||
|
||||
**Description**: 点乘。
|
||||
|
||||
**Arguments**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __matmul__(self, other: 'Vector3') -> 'RealNumber':
|
||||
"""
|
||||
点乘。
|
||||
Args:
|
||||
other:
|
||||
Returns:
|
||||
"""
|
||||
return self.x * other.x + self.y * other.y + self.z * other.z
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self / other: RealNumber => Vector3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __truediv__(self, other: RealNumber) -> 'Vector3':
|
||||
return Vector3(self.x / other, self.y / other, self.z / other)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `- self`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
def __neg__(self):
|
||||
return Vector3(-self.x, -self.y, -self.z)
|
||||
```
|
||||
</details>
|
||||
|
||||
### ***var*** `zero_vector3 = Vector3(0, 0, 0)`
|
||||
|
||||
- **Type**: `Vector3`
|
||||
|
||||
- **Description**: 零向量
|
||||
|
||||
### ***var*** `x_axis = Vector3(1, 0, 0)`
|
||||
|
||||
- **Type**: `Vector3`
|
||||
|
||||
- **Description**: x轴单位向量
|
||||
|
||||
### ***var*** `y_axis = Vector3(0, 1, 0)`
|
||||
|
||||
- **Type**: `Vector3`
|
||||
|
||||
- **Description**: y轴单位向量
|
||||
|
||||
### ***var*** `z_axis = Vector3(0, 0, 1)`
|
||||
|
||||
- **Type**: `Vector3`
|
||||
|
||||
- **Description**: z轴单位向量
|
||||
|
@ -1,3 +0,0 @@
|
||||
---
|
||||
title: mbcp.particle
|
||||
---
|
@ -1,3 +0,0 @@
|
||||
---
|
||||
title: mbcp.presets
|
||||
---
|
@ -1,43 +0,0 @@
|
||||
---
|
||||
title: mbcp.presets.model
|
||||
---
|
||||
### **class** `GeometricModels`
|
||||
### `@staticmethod`
|
||||
### *method* `sphere(radius: float, density: float)`
|
||||
|
||||
|
||||
|
||||
**Description**: 生成球体上的点集。
|
||||
|
||||
**Arguments**:
|
||||
> - radius:
|
||||
> - density:
|
||||
|
||||
**Return**: List[Point3]: 球体上的点集。
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>Source code</b> </summary>
|
||||
|
||||
```python
|
||||
@staticmethod
|
||||
def sphere(radius: float, density: float):
|
||||
"""
|
||||
生成球体上的点集。
|
||||
Args:
|
||||
radius:
|
||||
density:
|
||||
Returns:
|
||||
List[Point3]: 球体上的点集。
|
||||
"""
|
||||
area = 4 * np.pi * radius ** 2
|
||||
num = int(area * density)
|
||||
phi_list = np.arccos([clamp(-1 + (2.0 * _ - 1.0) / num, -1, 1) for _ in range(num)])
|
||||
theta_list = np.sqrt(num * np.pi) * phi_list
|
||||
x_array = radius * np.sin(phi_list) * np.cos(theta_list)
|
||||
y_array = radius * np.sin(phi_list) * np.sin(theta_list)
|
||||
z_array = radius * np.cos(phi_list)
|
||||
return [Point3(x_array[i], y_array[i], z_array[i]) for i in range(num)]
|
||||
```
|
||||
</details>
|
||||
|
@ -1,3 +0,0 @@
|
||||
---
|
||||
title: mbcp
|
||||
---
|
@ -1,399 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.angle
|
||||
---
|
||||
### **class** `Angle`
|
||||
### **class** `AnyAngle(Angle)`
|
||||
### *method* `__init__(self, value: float, is_radian: bool = False)`
|
||||
|
||||
|
||||
|
||||
**説明**: 任意角度。
|
||||
|
||||
**引数**:
|
||||
> - value: 角度或弧度值
|
||||
> - is_radian: 是否为弧度,默认为否
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, value: float, is_radian: bool=False):
|
||||
"""
|
||||
任意角度。
|
||||
Args:
|
||||
value: 角度或弧度值
|
||||
is_radian: 是否为弧度,默认为否
|
||||
"""
|
||||
if is_radian:
|
||||
self.radian = value
|
||||
else:
|
||||
self.radian = value * PI / 180
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `complementary(self) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**説明**: 余角:两角的和为90°。
|
||||
|
||||
**戻り値**: 余角
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def complementary(self) -> 'AnyAngle':
|
||||
"""
|
||||
余角:两角的和为90°。
|
||||
Returns:
|
||||
余角
|
||||
"""
|
||||
return AnyAngle(PI / 2 - self.minimum_positive.radian, is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `supplementary(self) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**説明**: 补角:两角的和为180°。
|
||||
|
||||
**戻り値**: 补角
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def supplementary(self) -> 'AnyAngle':
|
||||
"""
|
||||
补角:两角的和为180°。
|
||||
Returns:
|
||||
补角
|
||||
"""
|
||||
return AnyAngle(PI - self.minimum_positive.radian, is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `degree(self) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 角度。
|
||||
|
||||
**戻り値**: 弧度
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def degree(self) -> float:
|
||||
"""
|
||||
角度。
|
||||
Returns:
|
||||
弧度
|
||||
"""
|
||||
return self.radian * 180 / PI
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `minimum_positive(self) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**説明**: 最小正角。
|
||||
|
||||
**戻り値**: 最小正角度
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def minimum_positive(self) -> 'AnyAngle':
|
||||
"""
|
||||
最小正角。
|
||||
Returns:
|
||||
最小正角度
|
||||
"""
|
||||
return AnyAngle(self.radian % (2 * PI))
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `maximum_negative(self) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**説明**: 最大负角。
|
||||
|
||||
**戻り値**: 最大负角度
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def maximum_negative(self) -> 'AnyAngle':
|
||||
"""
|
||||
最大负角。
|
||||
Returns:
|
||||
最大负角度
|
||||
"""
|
||||
return AnyAngle(-self.radian % (2 * PI), is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `sin(self) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 正弦值。
|
||||
|
||||
**戻り値**: 正弦值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def sin(self) -> float:
|
||||
"""
|
||||
正弦值。
|
||||
Returns:
|
||||
正弦值
|
||||
"""
|
||||
return math.sin(self.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `cos(self) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 余弦值。
|
||||
|
||||
**戻り値**: 余弦值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def cos(self) -> float:
|
||||
"""
|
||||
余弦值。
|
||||
Returns:
|
||||
余弦值
|
||||
"""
|
||||
return math.cos(self.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `tan(self) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 正切值。
|
||||
|
||||
**戻り値**: 正切值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def tan(self) -> float:
|
||||
"""
|
||||
正切值。
|
||||
Returns:
|
||||
正切值
|
||||
"""
|
||||
return math.tan(self.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `cot(self) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 余切值。
|
||||
|
||||
**戻り値**: 余切值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def cot(self) -> float:
|
||||
"""
|
||||
余切值。
|
||||
Returns:
|
||||
余切值
|
||||
"""
|
||||
return 1 / math.tan(self.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `sec(self) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 正割值。
|
||||
|
||||
**戻り値**: 正割值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def sec(self) -> float:
|
||||
"""
|
||||
正割值。
|
||||
Returns:
|
||||
正割值
|
||||
"""
|
||||
return 1 / math.cos(self.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `csc(self) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 余割值。
|
||||
|
||||
**戻り値**: 余割值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def csc(self) -> float:
|
||||
"""
|
||||
余割值。
|
||||
Returns:
|
||||
余割值
|
||||
"""
|
||||
return 1 / math.sin(self.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self + other: AnyAngle => AnyAngle`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __add__(self, other: 'AnyAngle') -> 'AnyAngle':
|
||||
return AnyAngle(self.radian + other.radian, is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__eq__(self, other)`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __eq__(self, other):
|
||||
return approx(self.radian, other.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self - other: AnyAngle => AnyAngle`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __sub__(self, other: 'AnyAngle') -> 'AnyAngle':
|
||||
return AnyAngle(self.radian - other.radian, is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self * other: float => AnyAngle`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __mul__(self, other: float) -> 'AnyAngle':
|
||||
return AnyAngle(self.radian * other, is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self / other: float => AnyAngle`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __truediv__(self, other: float) -> 'AnyAngle':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self / other: AnyAngle => float`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __truediv__(self, other: 'AnyAngle') -> float:
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self / other`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __truediv__(self, other):
|
||||
if isinstance(other, AnyAngle):
|
||||
return self.radian / other.radian
|
||||
return AnyAngle(self.radian / other, is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
@ -1,3 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.const
|
||||
---
|
@ -1,151 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.equation
|
||||
---
|
||||
### *func* `get_partial_derivative_func(func: MultiVarsFunc = EPSILON) -> MultiVarsFunc`
|
||||
|
||||
|
||||
|
||||
**説明**: 求N元函数一阶偏导函数。这玩意不太稳定,慎用。
|
||||
|
||||
**引数**:
|
||||
> - func: 函数
|
||||
> - var: 变量位置,可为整数(一阶偏导)或整数元组(高阶偏导)
|
||||
> - epsilon: 偏移量
|
||||
|
||||
**戻り値**: 偏导函数
|
||||
|
||||
**例外**:
|
||||
> - ValueError 无效变量类型
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def get_partial_derivative_func(func: MultiVarsFunc, var: int | tuple[int, ...], epsilon: Number=EPSILON) -> MultiVarsFunc:
|
||||
"""
|
||||
求N元函数一阶偏导函数。这玩意不太稳定,慎用。
|
||||
Args:
|
||||
func: 函数
|
||||
var: 变量位置,可为整数(一阶偏导)或整数元组(高阶偏导)
|
||||
epsilon: 偏移量
|
||||
Returns:
|
||||
偏导函数
|
||||
Raises:
|
||||
ValueError: 无效变量类型
|
||||
"""
|
||||
if isinstance(var, int):
|
||||
|
||||
def partial_derivative_func(*args: Var) -> Var:
|
||||
args_list_plus = list(args)
|
||||
args_list_plus[var] += epsilon
|
||||
args_list_minus = list(args)
|
||||
args_list_minus[var] -= epsilon
|
||||
return (func(*args_list_plus) - func(*args_list_minus)) / (2 * epsilon)
|
||||
return partial_derivative_func
|
||||
elif isinstance(var, tuple):
|
||||
|
||||
def high_order_partial_derivative_func(*args: Var) -> Var:
|
||||
result_func = func
|
||||
for v in var:
|
||||
result_func = get_partial_derivative_func(result_func, v, epsilon)
|
||||
return result_func(*args)
|
||||
return high_order_partial_derivative_func
|
||||
else:
|
||||
raise ValueError('Invalid var type')
|
||||
```
|
||||
</details>
|
||||
|
||||
### *func* `partial_derivative_func() -> Var`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def partial_derivative_func(*args: Var) -> Var:
|
||||
args_list_plus = list(args)
|
||||
args_list_plus[var] += epsilon
|
||||
args_list_minus = list(args)
|
||||
args_list_minus[var] -= epsilon
|
||||
return (func(*args_list_plus) - func(*args_list_minus)) / (2 * epsilon)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *func* `high_order_partial_derivative_func() -> Var`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def high_order_partial_derivative_func(*args: Var) -> Var:
|
||||
result_func = func
|
||||
for v in var:
|
||||
result_func = get_partial_derivative_func(result_func, v, epsilon)
|
||||
return result_func(*args)
|
||||
```
|
||||
</details>
|
||||
|
||||
### **class** `CurveEquation`
|
||||
### *method* `__init__(self, x_func: OneVarFunc, y_func: OneVarFunc, z_func: OneVarFunc)`
|
||||
|
||||
|
||||
|
||||
**説明**: 曲线方程。
|
||||
|
||||
**引数**:
|
||||
> - x_func: x函数
|
||||
> - y_func: y函数
|
||||
> - z_func: z函数
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, x_func: OneVarFunc, y_func: OneVarFunc, z_func: OneVarFunc):
|
||||
"""
|
||||
曲线方程。
|
||||
Args:
|
||||
x_func: x函数
|
||||
y_func: y函数
|
||||
z_func: z函数
|
||||
"""
|
||||
self.x_func = x_func
|
||||
self.y_func = y_func
|
||||
self.z_func = z_func
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__call__(self) -> Point3 | tuple[Point3, ...]`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算曲线上的点。
|
||||
|
||||
**引数**:
|
||||
> - *t:
|
||||
> - 参数:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __call__(self, *t: Var) -> Point3 | tuple[Point3, ...]:
|
||||
"""
|
||||
计算曲线上的点。
|
||||
Args:
|
||||
*t:
|
||||
参数
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if len(t) == 1:
|
||||
return Point3(self.x_func(t[0]), self.y_func(t[0]), self.z_func(t[0]))
|
||||
else:
|
||||
return tuple([Point3(x, y, z) for x, y, z in zip(self.x_func(t), self.y_func(t), self.z_func(t))])
|
||||
```
|
||||
</details>
|
||||
|
@ -1,3 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math
|
||||
---
|
@ -1,530 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.line
|
||||
---
|
||||
### **class** `Line3`
|
||||
### *method* `__init__(self, point: Point3, direction: Vector3)`
|
||||
|
||||
|
||||
|
||||
**説明**: 三维空间中的直线。由一个点和一个方向向量确定。
|
||||
|
||||
**引数**:
|
||||
> - point: 直线上的一点
|
||||
> - direction: 直线的方向向量
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, point: 'Point3', direction: 'Vector3'):
|
||||
"""
|
||||
三维空间中的直线。由一个点和一个方向向量确定。
|
||||
Args:
|
||||
point: 直线上的一点
|
||||
direction: 直线的方向向量
|
||||
"""
|
||||
self.point = point
|
||||
self.direction = direction
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `approx(self, other: Line3, epsilon: float = APPROX) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两条直线是否近似相等。
|
||||
|
||||
**引数**:
|
||||
> - other: 另一条直线
|
||||
> - epsilon: 误差
|
||||
|
||||
**戻り値**: 是否近似相等
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def approx(self, other: 'Line3', epsilon: float=APPROX) -> bool:
|
||||
"""
|
||||
判断两条直线是否近似相等。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
epsilon: 误差
|
||||
Returns:
|
||||
是否近似相等
|
||||
"""
|
||||
return self.is_approx_parallel(other, epsilon) and (self.point - other.point).is_approx_parallel(self.direction, epsilon)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_angle(self, other: Line3) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算直线和直线之间的夹角。
|
||||
|
||||
**引数**:
|
||||
> - other: 另一条直线
|
||||
|
||||
**戻り値**: 夹角弧度
|
||||
|
||||
**例外**:
|
||||
> - TypeError 不支持的类型
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_angle(self, other: 'Line3') -> 'AnyAngle':
|
||||
"""
|
||||
计算直线和直线之间的夹角。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
Returns:
|
||||
夹角弧度
|
||||
Raises:
|
||||
TypeError: 不支持的类型
|
||||
"""
|
||||
return self.direction.cal_angle(other.direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_distance(self, other: Line3 | Point3) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算直线和直线或点之间的距离。
|
||||
|
||||
**引数**:
|
||||
> - other: 平行直线或点
|
||||
|
||||
**戻り値**: 距离
|
||||
|
||||
**例外**:
|
||||
> - TypeError 不支持的类型
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_distance(self, other: 'Line3 | Point3') -> float:
|
||||
"""
|
||||
计算直线和直线或点之间的距离。
|
||||
Args:
|
||||
other: 平行直线或点
|
||||
|
||||
Returns:
|
||||
距离
|
||||
Raises:
|
||||
TypeError: 不支持的类型
|
||||
"""
|
||||
if isinstance(other, Line3):
|
||||
if self == other:
|
||||
return 0
|
||||
elif self.is_parallel(other):
|
||||
return (other.point - self.point).cross(self.direction).length / self.direction.length
|
||||
elif not self.is_coplanar(other):
|
||||
return abs(self.direction.cross(other.direction) @ (self.point - other.point) / self.direction.cross(other.direction).length)
|
||||
else:
|
||||
return 0
|
||||
elif isinstance(other, Point3):
|
||||
return (other - self.point).cross(self.direction).length / self.direction.length
|
||||
else:
|
||||
raise TypeError('Unsupported type.')
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_intersection(self, other: Line3) -> Point3`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算两条直线的交点。
|
||||
|
||||
**引数**:
|
||||
> - other: 另一条直线
|
||||
|
||||
**戻り値**: 交点
|
||||
|
||||
**例外**:
|
||||
> - ValueError 直线平行
|
||||
> - ValueError 直线不共面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_intersection(self, other: 'Line3') -> 'Point3':
|
||||
"""
|
||||
计算两条直线的交点。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
Returns:
|
||||
交点
|
||||
Raises:
|
||||
ValueError: 直线平行
|
||||
ValueError: 直线不共面
|
||||
"""
|
||||
if self.is_parallel(other):
|
||||
raise ValueError('Lines are parallel and do not intersect.')
|
||||
if not self.is_coplanar(other):
|
||||
raise ValueError('Lines are not coplanar and do not intersect.')
|
||||
return self.point + self.direction.cross(other.direction) @ other.direction.cross(self.point - other.point) / self.direction.cross(other.direction).length ** 2 * self.direction
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_perpendicular(self, point: Point3) -> Line3`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算直线经过指定点p的垂线。
|
||||
|
||||
**引数**:
|
||||
> - point: 指定点
|
||||
|
||||
**戻り値**: 垂线
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_perpendicular(self, point: 'Point3') -> 'Line3':
|
||||
"""
|
||||
计算直线经过指定点p的垂线。
|
||||
Args:
|
||||
point: 指定点
|
||||
Returns:
|
||||
垂线
|
||||
"""
|
||||
return Line3(point, self.direction.cross(point - self.point))
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `get_point(self, t: RealNumber) -> Point3`
|
||||
|
||||
|
||||
|
||||
**説明**: 获取直线上的点。同一条直线,但起始点和方向向量不同,则同一个t对应的点不同。
|
||||
|
||||
**引数**:
|
||||
> - t: 参数t
|
||||
|
||||
**戻り値**: 点
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def get_point(self, t: RealNumber) -> 'Point3':
|
||||
"""
|
||||
获取直线上的点。同一条直线,但起始点和方向向量不同,则同一个t对应的点不同。
|
||||
Args:
|
||||
t: 参数t
|
||||
Returns:
|
||||
点
|
||||
"""
|
||||
return self.point + t * self.direction
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `get_parametric_equations(self) -> tuple[OneSingleVarFunc, OneSingleVarFunc, OneSingleVarFunc]`
|
||||
|
||||
|
||||
|
||||
**説明**: 获取直线的参数方程。
|
||||
|
||||
**戻り値**: x(t), y(t), z(t)
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def get_parametric_equations(self) -> tuple[OneSingleVarFunc, OneSingleVarFunc, OneSingleVarFunc]:
|
||||
"""
|
||||
获取直线的参数方程。
|
||||
Returns:
|
||||
x(t), y(t), z(t)
|
||||
"""
|
||||
return (lambda t: self.point.x + self.direction.x * t, lambda t: self.point.y + self.direction.y * t, lambda t: self.point.z + self.direction.z * t)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_approx_parallel(self, other: Line3, epsilon: float = 1e-06) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两条直线是否近似平行。
|
||||
|
||||
**引数**:
|
||||
> - other: 另一条直线
|
||||
> - epsilon: 误差
|
||||
|
||||
**戻り値**: 是否近似平行
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def is_approx_parallel(self, other: 'Line3', epsilon: float=1e-06) -> bool:
|
||||
"""
|
||||
判断两条直线是否近似平行。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
epsilon: 误差
|
||||
Returns:
|
||||
是否近似平行
|
||||
"""
|
||||
return self.direction.is_approx_parallel(other.direction, epsilon)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_parallel(self, other: Line3) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两条直线是否平行。
|
||||
|
||||
**引数**:
|
||||
> - other: 另一条直线
|
||||
|
||||
**戻り値**: 是否平行
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def is_parallel(self, other: 'Line3') -> bool:
|
||||
"""
|
||||
判断两条直线是否平行。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
Returns:
|
||||
是否平行
|
||||
"""
|
||||
return self.direction.is_parallel(other.direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_collinear(self, other: Line3) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两条直线是否共线。
|
||||
|
||||
**引数**:
|
||||
> - other: 另一条直线
|
||||
|
||||
**戻り値**: 是否共线
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def is_collinear(self, other: 'Line3') -> bool:
|
||||
"""
|
||||
判断两条直线是否共线。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
Returns:
|
||||
是否共线
|
||||
"""
|
||||
return self.is_parallel(other) and (self.point - other.point).is_parallel(self.direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_point_on(self, point: Point3) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断点是否在直线上。
|
||||
|
||||
**引数**:
|
||||
> - point: 点
|
||||
|
||||
**戻り値**: 是否在直线上
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def is_point_on(self, point: 'Point3') -> bool:
|
||||
"""
|
||||
判断点是否在直线上。
|
||||
Args:
|
||||
point: 点
|
||||
Returns:
|
||||
是否在直线上
|
||||
"""
|
||||
return (point - self.point).is_parallel(self.direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_coplanar(self, other: Line3) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两条直线是否共面。
|
||||
充要条件:两直线方向向量的叉乘与两直线上任意一点的向量的点积为0。
|
||||
|
||||
**引数**:
|
||||
> - other: 另一条直线
|
||||
|
||||
**戻り値**: 是否共面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def is_coplanar(self, other: 'Line3') -> bool:
|
||||
"""
|
||||
判断两条直线是否共面。
|
||||
充要条件:两直线方向向量的叉乘与两直线上任意一点的向量的点积为0。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
Returns:
|
||||
是否共面
|
||||
"""
|
||||
return self.direction.cross(other.direction) @ (self.point - other.point) == 0
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `simplify(self)`
|
||||
|
||||
|
||||
|
||||
**説明**: 简化直线方程,等价相等。
|
||||
自体简化,不返回值。
|
||||
|
||||
按照可行性一次对x y z 化 0 处理,并对向量单位化
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def simplify(self):
|
||||
"""
|
||||
简化直线方程,等价相等。
|
||||
自体简化,不返回值。
|
||||
|
||||
按照可行性一次对x y z 化 0 处理,并对向量单位化
|
||||
"""
|
||||
self.direction.normalize()
|
||||
if self.direction.x == 0:
|
||||
self.point.x = 0
|
||||
if self.direction.y == 0:
|
||||
self.point.y = 0
|
||||
if self.direction.z == 0:
|
||||
self.point.z = 0
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@classmethod`
|
||||
### *method* `from_two_points(cls, p1: Point3, p2: Point3) -> Line3`
|
||||
|
||||
|
||||
|
||||
**説明**: 工厂函数 由两点构造直线。
|
||||
|
||||
**引数**:
|
||||
> - p1: 点1
|
||||
> - p2: 点2
|
||||
|
||||
**戻り値**: 直线
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@classmethod
|
||||
def from_two_points(cls, p1: 'Point3', p2: 'Point3') -> 'Line3':
|
||||
"""
|
||||
工厂函数 由两点构造直线。
|
||||
Args:
|
||||
p1: 点1
|
||||
p2: 点2
|
||||
Returns:
|
||||
直线
|
||||
"""
|
||||
direction = p2 - p1
|
||||
return cls(p1, direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__and__(self, other: Line3) -> Line3 | Point3 | None`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算两条直线点集合的交集。重合线返回自身,平行线返回None,交线返回交点。
|
||||
|
||||
**引数**:
|
||||
> - other: 另一条直线
|
||||
|
||||
**戻り値**: 交点
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __and__(self, other: 'Line3') -> 'Line3 | Point3 | None':
|
||||
"""
|
||||
计算两条直线点集合的交集。重合线返回自身,平行线返回None,交线返回交点。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
Returns:
|
||||
交点
|
||||
"""
|
||||
if self.is_collinear(other):
|
||||
return self
|
||||
elif self.is_parallel(other) or not self.is_coplanar(other):
|
||||
return None
|
||||
else:
|
||||
return self.cal_intersection(other)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__eq__(self, other) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两条直线是否等价。
|
||||
|
||||
v1 // v2 ∧ (p1 - p2) // v1
|
||||
|
||||
**引数**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __eq__(self, other) -> bool:
|
||||
"""
|
||||
判断两条直线是否等价。
|
||||
|
||||
v1 // v2 ∧ (p1 - p2) // v1
|
||||
Args:
|
||||
other:
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
return self.direction.is_parallel(other.direction) and (self.point - other.point).is_parallel(self.direction)
|
||||
```
|
||||
</details>
|
||||
|
@ -1,63 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.mp_math_typing
|
||||
---
|
||||
### ***var*** `RealNumber = int | float`
|
||||
|
||||
- **タイプ**: `TypeAlias`
|
||||
|
||||
### ***var*** `Number = RealNumber | complex`
|
||||
|
||||
- **タイプ**: `TypeAlias`
|
||||
|
||||
### ***var*** `Var = SingleVar | ArrayVar`
|
||||
|
||||
- **タイプ**: `TypeAlias`
|
||||
|
||||
### ***var*** `OneSingleVarFunc = Callable[[SingleVar], SingleVar]`
|
||||
|
||||
- **タイプ**: `TypeAlias`
|
||||
|
||||
### ***var*** `OneArrayFunc = Callable[[ArrayVar], ArrayVar]`
|
||||
|
||||
- **タイプ**: `TypeAlias`
|
||||
|
||||
### ***var*** `OneVarFunc = OneSingleVarFunc | OneArrayFunc`
|
||||
|
||||
- **タイプ**: `TypeAlias`
|
||||
|
||||
### ***var*** `TwoSingleVarsFunc = Callable[[SingleVar, SingleVar], SingleVar]`
|
||||
|
||||
- **タイプ**: `TypeAlias`
|
||||
|
||||
### ***var*** `TwoArraysFunc = Callable[[ArrayVar, ArrayVar], ArrayVar]`
|
||||
|
||||
- **タイプ**: `TypeAlias`
|
||||
|
||||
### ***var*** `TwoVarsFunc = TwoSingleVarsFunc | TwoArraysFunc`
|
||||
|
||||
- **タイプ**: `TypeAlias`
|
||||
|
||||
### ***var*** `ThreeSingleVarsFunc = Callable[[SingleVar, SingleVar, SingleVar], SingleVar]`
|
||||
|
||||
- **タイプ**: `TypeAlias`
|
||||
|
||||
### ***var*** `ThreeArraysFunc = Callable[[ArrayVar, ArrayVar, ArrayVar], ArrayVar]`
|
||||
|
||||
- **タイプ**: `TypeAlias`
|
||||
|
||||
### ***var*** `ThreeVarsFunc = ThreeSingleVarsFunc | ThreeArraysFunc`
|
||||
|
||||
- **タイプ**: `TypeAlias`
|
||||
|
||||
### ***var*** `MultiSingleVarsFunc = Callable[..., SingleVar]`
|
||||
|
||||
- **タイプ**: `TypeAlias`
|
||||
|
||||
### ***var*** `MultiArraysFunc = Callable[..., ArrayVar]`
|
||||
|
||||
- **タイプ**: `TypeAlias`
|
||||
|
||||
### ***var*** `MultiVarsFunc = MultiSingleVarsFunc | MultiArraysFunc`
|
||||
|
||||
- **タイプ**: `TypeAlias`
|
||||
|
@ -1,542 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.plane
|
||||
---
|
||||
### **class** `Plane3`
|
||||
### *method* `__init__(self, a: float, b: float, c: float, d: float)`
|
||||
|
||||
|
||||
|
||||
**説明**: 平面方程:ax + by + cz + d = 0
|
||||
|
||||
**引数**:
|
||||
> - a: x系数
|
||||
> - b: y系数
|
||||
> - c: z系数
|
||||
> - d: 常数项
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, a: float, b: float, c: float, d: float):
|
||||
"""
|
||||
平面方程:ax + by + cz + d = 0
|
||||
Args:
|
||||
a: x系数
|
||||
b: y系数
|
||||
c: z系数
|
||||
d: 常数项
|
||||
"""
|
||||
self.a = a
|
||||
self.b = b
|
||||
self.c = c
|
||||
self.d = d
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `approx(self, other: Plane3) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两个平面是否近似相等。
|
||||
|
||||
**引数**:
|
||||
> - other: 另一个平面
|
||||
|
||||
**戻り値**: 是否近似相等
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def approx(self, other: 'Plane3') -> bool:
|
||||
"""
|
||||
判断两个平面是否近似相等。
|
||||
Args:
|
||||
other: 另一个平面
|
||||
Returns:
|
||||
是否近似相等
|
||||
"""
|
||||
if self.a != 0:
|
||||
k = other.a / self.a
|
||||
return approx(other.b, self.b * k) and approx(other.c, self.c * k) and approx(other.d, self.d * k)
|
||||
elif self.b != 0:
|
||||
k = other.b / self.b
|
||||
return approx(other.a, self.a * k) and approx(other.c, self.c * k) and approx(other.d, self.d * k)
|
||||
elif self.c != 0:
|
||||
k = other.c / self.c
|
||||
return approx(other.a, self.a * k) and approx(other.b, self.b * k) and approx(other.d, self.d * k)
|
||||
else:
|
||||
return False
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_angle(self, other: Line3 | Plane3) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算平面与平面之间的夹角。
|
||||
|
||||
**引数**:
|
||||
> - other: 另一个平面
|
||||
|
||||
**戻り値**: 夹角弧度
|
||||
|
||||
**例外**:
|
||||
> - TypeError 不支持的类型
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_angle(self, other: 'Line3 | Plane3') -> 'AnyAngle':
|
||||
"""
|
||||
计算平面与平面之间的夹角。
|
||||
Args:
|
||||
other: 另一个平面
|
||||
Returns:
|
||||
夹角弧度
|
||||
Raises:
|
||||
TypeError: 不支持的类型
|
||||
"""
|
||||
if isinstance(other, Line3):
|
||||
return self.normal.cal_angle(other.direction).complementary
|
||||
elif isinstance(other, Plane3):
|
||||
return AnyAngle(math.acos(self.normal @ other.normal / (self.normal.length * other.normal.length)), is_radian=True)
|
||||
else:
|
||||
raise TypeError(f'Unsupported type: {type(other)}')
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_distance(self, other: Plane3 | Point3) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算平面与平面或点之间的距离。
|
||||
|
||||
**引数**:
|
||||
> - other: 另一个平面或点
|
||||
|
||||
**戻り値**: 距离
|
||||
|
||||
**例外**:
|
||||
> - TypeError 不支持的类型
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_distance(self, other: 'Plane3 | Point3') -> float:
|
||||
"""
|
||||
计算平面与平面或点之间的距离。
|
||||
Args:
|
||||
other: 另一个平面或点
|
||||
Returns:
|
||||
距离
|
||||
Raises:
|
||||
TypeError: 不支持的类型
|
||||
"""
|
||||
if isinstance(other, Plane3):
|
||||
return 0
|
||||
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:
|
||||
raise TypeError(f'Unsupported type: {type(other)}')
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_intersection_line3(self, other: Plane3) -> Line3`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算两平面的交线。
|
||||
|
||||
**引数**:
|
||||
> - other: 另一个平面
|
||||
|
||||
**戻り値**: 两平面的交线
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_intersection_line3(self, other: 'Plane3') -> 'Line3':
|
||||
"""
|
||||
计算两平面的交线。
|
||||
Args:
|
||||
other: 另一个平面
|
||||
Returns:
|
||||
两平面的交线
|
||||
Raises:
|
||||
"""
|
||||
if self.normal.is_parallel(other.normal):
|
||||
raise ValueError('Planes are parallel and have no intersection.')
|
||||
direction = self.normal.cross(other.normal)
|
||||
x, y, z = (0, 0, 0)
|
||||
if self.a != 0 and other.a != 0:
|
||||
A = np.array([[self.b, self.c], [other.b, other.c]])
|
||||
B = np.array([-self.d, -other.d])
|
||||
y, z = np.linalg.solve(A, B)
|
||||
elif self.b != 0 and other.b != 0:
|
||||
A = np.array([[self.a, self.c], [other.a, other.c]])
|
||||
B = np.array([-self.d, -other.d])
|
||||
x, z = np.linalg.solve(A, B)
|
||||
elif self.c != 0 and other.c != 0:
|
||||
A = np.array([[self.a, self.b], [other.a, other.b]])
|
||||
B = np.array([-self.d, -other.d])
|
||||
x, y = np.linalg.solve(A, B)
|
||||
return Line3(Point3(x, y, z), direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_intersection_point3(self, other: Line3) -> Point3`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算平面与直线的交点。
|
||||
|
||||
**引数**:
|
||||
> - other: 不与平面平行或在平面上的直线
|
||||
|
||||
**戻り値**: 交点
|
||||
|
||||
**例外**:
|
||||
> - ValueError 平面与直线平行或重合
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_intersection_point3(self, other: 'Line3') -> 'Point3':
|
||||
"""
|
||||
计算平面与直线的交点。
|
||||
Args:
|
||||
other: 不与平面平行或在平面上的直线
|
||||
Returns:
|
||||
交点
|
||||
Raises:
|
||||
ValueError: 平面与直线平行或重合
|
||||
"""
|
||||
if self.normal @ other.direction == 0:
|
||||
raise ValueError('The plane and the line are parallel or coincident.')
|
||||
x, y, z = other.get_parametric_equations()
|
||||
t = -(self.a * other.point.x + self.b * other.point.y + self.c * other.point.z + self.d) / (self.a * other.direction.x + self.b * other.direction.y + self.c * other.direction.z)
|
||||
return Point3(x(t), y(t), z(t))
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_parallel_plane3(self, point: Point3) -> Plane3`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算平行于该平面且过指定点的平面。
|
||||
|
||||
**引数**:
|
||||
> - point: 指定点
|
||||
|
||||
**戻り値**: 所求平面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_parallel_plane3(self, point: 'Point3') -> 'Plane3':
|
||||
"""
|
||||
计算平行于该平面且过指定点的平面。
|
||||
Args:
|
||||
point: 指定点
|
||||
Returns:
|
||||
所求平面
|
||||
"""
|
||||
return Plane3.from_point_and_normal(point, self.normal)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_parallel(self, other: Plane3) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两个平面是否平行。
|
||||
|
||||
**引数**:
|
||||
> - other: 另一个平面
|
||||
|
||||
**戻り値**: 是否平行
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def is_parallel(self, other: 'Plane3') -> bool:
|
||||
"""
|
||||
判断两个平面是否平行。
|
||||
Args:
|
||||
other: 另一个平面
|
||||
Returns:
|
||||
是否平行
|
||||
"""
|
||||
return self.normal.is_parallel(other.normal)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `normal(self) -> Vector3`
|
||||
|
||||
|
||||
|
||||
**説明**: 平面的法向量。
|
||||
|
||||
**戻り値**: 法向量
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def normal(self) -> 'Vector3':
|
||||
"""
|
||||
平面的法向量。
|
||||
Returns:
|
||||
法向量
|
||||
"""
|
||||
return Vector3(self.a, self.b, self.c)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@classmethod`
|
||||
### *method* `from_point_and_normal(cls, point: Point3, normal: Vector3) -> Plane3`
|
||||
|
||||
|
||||
|
||||
**説明**: 工厂函数 由点和法向量构造平面(点法式构造)。
|
||||
|
||||
**引数**:
|
||||
> - point: 平面上的一点
|
||||
> - normal: 法向量
|
||||
|
||||
**戻り値**: 平面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@classmethod
|
||||
def from_point_and_normal(cls, point: 'Point3', normal: 'Vector3') -> 'Plane3':
|
||||
"""
|
||||
工厂函数 由点和法向量构造平面(点法式构造)。
|
||||
Args:
|
||||
point: 平面上的一点
|
||||
normal: 法向量
|
||||
Returns:
|
||||
平面
|
||||
"""
|
||||
a, b, c = (normal.x, normal.y, normal.z)
|
||||
d = -a * point.x - b * point.y - c * point.z
|
||||
return cls(a, b, c, d)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@classmethod`
|
||||
### *method* `from_three_points(cls, p1: Point3, p2: Point3, p3: Point3) -> Plane3`
|
||||
|
||||
|
||||
|
||||
**説明**: 工厂函数 由三点构造平面。
|
||||
|
||||
**引数**:
|
||||
> - p1: 点1
|
||||
> - p2: 点2
|
||||
> - p3: 点3
|
||||
|
||||
**戻り値**: 平面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@classmethod
|
||||
def from_three_points(cls, p1: 'Point3', p2: 'Point3', p3: 'Point3') -> 'Plane3':
|
||||
"""
|
||||
工厂函数 由三点构造平面。
|
||||
Args:
|
||||
p1: 点1
|
||||
p2: 点2
|
||||
p3: 点3
|
||||
Returns:
|
||||
平面
|
||||
"""
|
||||
v1 = p2 - p1
|
||||
v2 = p3 - p1
|
||||
normal = v1.cross(v2)
|
||||
return cls.from_point_and_normal(p1, normal)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@classmethod`
|
||||
### *method* `from_two_lines(cls, l1: Line3, l2: Line3) -> Plane3`
|
||||
|
||||
|
||||
|
||||
**説明**: 工厂函数 由两直线构造平面。
|
||||
|
||||
**引数**:
|
||||
> - l1: 直线1
|
||||
> - l2: 直线2
|
||||
|
||||
**戻り値**: 平面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@classmethod
|
||||
def from_two_lines(cls, l1: 'Line3', l2: 'Line3') -> 'Plane3':
|
||||
"""
|
||||
工厂函数 由两直线构造平面。
|
||||
Args:
|
||||
l1: 直线1
|
||||
l2: 直线2
|
||||
Returns:
|
||||
平面
|
||||
"""
|
||||
v1 = l1.direction
|
||||
v2 = l2.point - l1.point
|
||||
if v2 == zero_vector3:
|
||||
v2 = l2.get_point(1) - l1.point
|
||||
return cls.from_point_and_normal(l1.point, v1.cross(v2))
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@classmethod`
|
||||
### *method* `from_point_and_line(cls, point: Point3, line: Line3) -> Plane3`
|
||||
|
||||
|
||||
|
||||
**説明**: 工厂函数 由点和直线构造平面。
|
||||
|
||||
**引数**:
|
||||
> - point: 面上一点
|
||||
> - line: 面上直线,不包含点
|
||||
|
||||
**戻り値**: 平面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@classmethod
|
||||
def from_point_and_line(cls, point: 'Point3', line: 'Line3') -> 'Plane3':
|
||||
"""
|
||||
工厂函数 由点和直线构造平面。
|
||||
Args:
|
||||
point: 面上一点
|
||||
line: 面上直线,不包含点
|
||||
Returns:
|
||||
平面
|
||||
"""
|
||||
return cls.from_point_and_normal(point, line.direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `__and__(self, other: Line3) -> Point3 | None`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __and__(self, other: 'Line3') -> 'Point3 | None':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `__and__(self, other: Plane3) -> Line3 | None`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __and__(self, other: 'Plane3') -> 'Line3 | None':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__and__(self, other)`
|
||||
|
||||
|
||||
|
||||
**説明**: 取两平面的交集(人话:交线)
|
||||
|
||||
**引数**:
|
||||
> - other:
|
||||
|
||||
**戻り値**: 不平行平面的交线,平面平行返回None
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __and__(self, other):
|
||||
"""
|
||||
取两平面的交集(人话:交线)
|
||||
Args:
|
||||
other:
|
||||
Returns:
|
||||
不平行平面的交线,平面平行返回None
|
||||
"""
|
||||
if isinstance(other, Plane3):
|
||||
if self.normal.is_parallel(other.normal):
|
||||
return None
|
||||
return self.cal_intersection_line3(other)
|
||||
elif isinstance(other, Line3):
|
||||
if self.normal @ other.direction == 0:
|
||||
return None
|
||||
return self.cal_intersection_point3(other)
|
||||
else:
|
||||
raise TypeError(f"unsupported operand type(s) for &: 'Plane3' and '{type(other)}'")
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__eq__(self, other) -> bool`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __eq__(self, other) -> bool:
|
||||
return self.approx(other)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__rand__(self, other: Line3) -> Point3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __rand__(self, other: 'Line3') -> 'Point3':
|
||||
return self.cal_intersection_point3(other)
|
||||
```
|
||||
</details>
|
||||
|
@ -1,176 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.point
|
||||
---
|
||||
### **class** `Point3`
|
||||
### *method* `__init__(self, x: float, y: float, z: float)`
|
||||
|
||||
|
||||
|
||||
**説明**: 笛卡尔坐标系中的点。
|
||||
|
||||
**引数**:
|
||||
> - x: x 坐标
|
||||
> - y: y 坐标
|
||||
> - z: z 坐标
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```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>
|
||||
|
||||
### *method* `approx(self, other: Point3, epsilon: float = APPROX) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两个点是否近似相等。
|
||||
|
||||
**引数**:
|
||||
> - other:
|
||||
> - epsilon:
|
||||
|
||||
**戻り値**: 是否近似相等
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```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>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self + other: Vector3 => Point3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __add__(self, other: 'Vector3') -> 'Point3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self + other: Point3 => Point3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __add__(self, other: 'Point3') -> 'Point3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self + other`
|
||||
|
||||
|
||||
|
||||
**説明**: P + V -> P
|
||||
P + P -> P
|
||||
|
||||
**引数**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```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>
|
||||
|
||||
### *method* `__eq__(self, other)`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两个点是否相等。
|
||||
|
||||
**引数**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```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>
|
||||
|
||||
### *method* `self - other: Point3 => Vector3`
|
||||
|
||||
|
||||
|
||||
**説明**: P - P -> V
|
||||
|
||||
P - V -> P 已在 :class:`Vector3` 中实现
|
||||
|
||||
**引数**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```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>
|
||||
|
@ -1,34 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.segment
|
||||
---
|
||||
### **class** `Segment3`
|
||||
### *method* `__init__(self, p1: Point3, p2: Point3)`
|
||||
|
||||
|
||||
|
||||
**説明**: 三维空间中的线段。
|
||||
:param p1:
|
||||
:param p2:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, p1: 'Point3', p2: 'Point3'):
|
||||
"""
|
||||
三维空间中的线段。
|
||||
:param p1:
|
||||
:param p2:
|
||||
"""
|
||||
self.p1 = p1
|
||||
self.p2 = p2
|
||||
'方向向量'
|
||||
self.direction = self.p2 - self.p1
|
||||
'长度'
|
||||
self.length = self.direction.length
|
||||
'中心点'
|
||||
self.midpoint = Point3((self.p1.x + self.p2.x) / 2, (self.p1.y + self.p2.y) / 2, (self.p1.z + self.p2.z) / 2)
|
||||
```
|
||||
</details>
|
||||
|
@ -1,200 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.utils
|
||||
---
|
||||
### *func* `clamp() -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 区间限定函数
|
||||
|
||||
**引数**:
|
||||
> - x: 待限定的值
|
||||
> - min_: 最小值
|
||||
> - max_: 最大值
|
||||
|
||||
**戻り値**: 限制后的值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def clamp(x: float, min_: float, max_: float) -> float:
|
||||
"""
|
||||
区间限定函数
|
||||
Args:
|
||||
x: 待限定的值
|
||||
min_: 最小值
|
||||
max_: 最大值
|
||||
|
||||
Returns:
|
||||
限制后的值
|
||||
"""
|
||||
return max(min(x, max_), min_)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *func* `approx(x: float = 0.0, y: float = APPROX) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两个数是否近似相等。或包装一个实数,用于判断是否近似于0。
|
||||
|
||||
**引数**:
|
||||
> - x: 数1
|
||||
> - y: 数2
|
||||
> - epsilon: 误差
|
||||
|
||||
**戻り値**: 是否近似相等
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def approx(x: float, y: float=0.0, epsilon: float=APPROX) -> bool:
|
||||
"""
|
||||
判断两个数是否近似相等。或包装一个实数,用于判断是否近似于0。
|
||||
Args:
|
||||
x: 数1
|
||||
y: 数2
|
||||
epsilon: 误差
|
||||
Returns:
|
||||
是否近似相等
|
||||
"""
|
||||
return abs(x - y) < epsilon
|
||||
```
|
||||
</details>
|
||||
|
||||
### *func* `sign(x: float = False) -> str`
|
||||
|
||||
|
||||
|
||||
**説明**: 获取数的符号。
|
||||
|
||||
**引数**:
|
||||
> - x: 数
|
||||
> - only_neg: 是否只返回负数的符号
|
||||
|
||||
**戻り値**: 符号 + - ""
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def sign(x: float, only_neg: bool=False) -> str:
|
||||
"""获取数的符号。
|
||||
Args:
|
||||
x: 数
|
||||
only_neg: 是否只返回负数的符号
|
||||
Returns:
|
||||
符号 + - ""
|
||||
"""
|
||||
if x > 0:
|
||||
return '+' if not only_neg else ''
|
||||
elif x < 0:
|
||||
return '-'
|
||||
else:
|
||||
return ''
|
||||
```
|
||||
</details>
|
||||
|
||||
### *func* `sign_format(x: float = False) -> str`
|
||||
|
||||
|
||||
|
||||
**説明**: 格式化符号数
|
||||
-1 -> -1
|
||||
1 -> +1
|
||||
0 -> ""
|
||||
|
||||
**引数**:
|
||||
> - x: 数
|
||||
> - only_neg: 是否只返回负数的符号
|
||||
|
||||
**戻り値**: 符号 + - ""
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def sign_format(x: float, only_neg: bool=False) -> str:
|
||||
"""格式化符号数
|
||||
-1 -> -1
|
||||
1 -> +1
|
||||
0 -> ""
|
||||
Args:
|
||||
x: 数
|
||||
only_neg: 是否只返回负数的符号
|
||||
Returns:
|
||||
符号 + - ""
|
||||
"""
|
||||
if x > 0:
|
||||
return f'+{x}' if not only_neg else f'{x}'
|
||||
elif x < 0:
|
||||
return f'-{abs(x)}'
|
||||
else:
|
||||
return ''
|
||||
```
|
||||
</details>
|
||||
|
||||
### **class** `Approx`
|
||||
### *method* `__init__(self, value: RealNumber)`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, value: RealNumber):
|
||||
self.value = value
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__eq__(self, other)`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __eq__(self, other):
|
||||
if isinstance(self.value, (float, int)):
|
||||
if isinstance(other, (float, int)):
|
||||
return abs(self.value - other) < APPROX
|
||||
else:
|
||||
self.raise_type_error(other)
|
||||
elif isinstance(self.value, Vector3):
|
||||
if isinstance(other, (Vector3, Point3, Plane3, Line3)):
|
||||
return all([approx(self.value.x, other.x), approx(self.value.y, other.y), approx(self.value.z, other.z)])
|
||||
else:
|
||||
self.raise_type_error(other)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `raise_type_error(self, other)`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def raise_type_error(self, other):
|
||||
raise TypeError(f'Unsupported type: {type(self.value)} and {type(other)}')
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__ne__(self, other)`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
```
|
||||
</details>
|
||||
|
@ -1,656 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.vector
|
||||
---
|
||||
### **class** `Vector3`
|
||||
### *method* `__init__(self, x: float, y: float, z: float)`
|
||||
|
||||
|
||||
|
||||
**説明**: 3维向量
|
||||
|
||||
**引数**:
|
||||
> - x: x轴分量
|
||||
> - y: y轴分量
|
||||
> - z: z轴分量
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, x: float, y: float, z: float):
|
||||
"""
|
||||
3维向量
|
||||
Args:
|
||||
x: x轴分量
|
||||
y: y轴分量
|
||||
z: z轴分量
|
||||
"""
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.z = z
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `approx(self, other: Vector3, epsilon: float = APPROX) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两个向量是否近似相等。
|
||||
|
||||
**引数**:
|
||||
> - other:
|
||||
> - epsilon:
|
||||
|
||||
**戻り値**: 是否近似相等
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def approx(self, other: 'Vector3', 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>
|
||||
|
||||
### *method* `cal_angle(self, other: Vector3) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算两个向量之间的夹角。
|
||||
|
||||
**引数**:
|
||||
> - other: 另一个向量
|
||||
|
||||
**戻り値**: 夹角
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_angle(self, other: 'Vector3') -> 'AnyAngle':
|
||||
"""
|
||||
计算两个向量之间的夹角。
|
||||
Args:
|
||||
other: 另一个向量
|
||||
Returns:
|
||||
夹角
|
||||
"""
|
||||
return AnyAngle(math.acos(self @ other / (self.length * other.length)), is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cross(self, other: Vector3) -> Vector3`
|
||||
|
||||
|
||||
|
||||
**説明**: 向量积 叉乘:v1 cross v2 -> v3
|
||||
|
||||
叉乘为0,则两向量平行。
|
||||
其余结果的模为平行四边形的面积。
|
||||
|
||||
|
||||
**引数**:
|
||||
> - other:
|
||||
|
||||
**戻り値**: 行列式的结果
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def cross(self, other: 'Vector3') -> 'Vector3':
|
||||
"""
|
||||
向量积 叉乘:v1 cross v2 -> v3
|
||||
|
||||
叉乘为0,则两向量平行。
|
||||
其余结果的模为平行四边形的面积。
|
||||
|
||||
返回如下行列式的结果:
|
||||
|
||||
``i j k``
|
||||
|
||||
``x1 y1 z1``
|
||||
|
||||
``x2 y2 z2``
|
||||
|
||||
Args:
|
||||
other:
|
||||
Returns:
|
||||
行列式的结果
|
||||
"""
|
||||
return Vector3(self.y * other.z - self.z * other.y, self.z * other.x - self.x * other.z, self.x * other.y - self.y * other.x)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_approx_parallel(self, other: Vector3, epsilon: float = APPROX) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两个向量是否近似平行。
|
||||
|
||||
**引数**:
|
||||
> - other: 另一个向量
|
||||
> - epsilon: 允许的误差
|
||||
|
||||
**戻り値**: 是否近似平行
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def is_approx_parallel(self, other: 'Vector3', epsilon: float=APPROX) -> bool:
|
||||
"""
|
||||
判断两个向量是否近似平行。
|
||||
Args:
|
||||
other: 另一个向量
|
||||
epsilon: 允许的误差
|
||||
Returns:
|
||||
是否近似平行
|
||||
"""
|
||||
return self.cross(other).length < epsilon
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_parallel(self, other: Vector3) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两个向量是否平行。
|
||||
|
||||
**引数**:
|
||||
> - other: 另一个向量
|
||||
|
||||
**戻り値**: 是否平行
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def is_parallel(self, other: 'Vector3') -> bool:
|
||||
"""
|
||||
判断两个向量是否平行。
|
||||
Args:
|
||||
other: 另一个向量
|
||||
Returns:
|
||||
是否平行
|
||||
"""
|
||||
return self.cross(other).approx(zero_vector3)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `normalize(self)`
|
||||
|
||||
|
||||
|
||||
**説明**: 将向量归一化。
|
||||
|
||||
自体归一化,不返回值。
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def normalize(self):
|
||||
"""
|
||||
将向量归一化。
|
||||
|
||||
自体归一化,不返回值。
|
||||
"""
|
||||
length = self.length
|
||||
self.x /= length
|
||||
self.y /= length
|
||||
self.z /= length
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `np_array(self) -> np.ndarray`
|
||||
|
||||
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def np_array(self) -> 'np.ndarray':
|
||||
"""
|
||||
返回numpy数组
|
||||
Returns:
|
||||
"""
|
||||
return np.array([self.x, self.y, self.z])
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `length(self) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 向量的模。
|
||||
|
||||
**戻り値**: 模
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def length(self) -> float:
|
||||
"""
|
||||
向量的模。
|
||||
Returns:
|
||||
模
|
||||
"""
|
||||
return math.sqrt(self.x ** 2 + self.y ** 2 + self.z ** 2)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `unit(self) -> Vector3`
|
||||
|
||||
|
||||
|
||||
**説明**: 获取该向量的单位向量。
|
||||
|
||||
**戻り値**: 单位向量
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def unit(self) -> 'Vector3':
|
||||
"""
|
||||
获取该向量的单位向量。
|
||||
Returns:
|
||||
单位向量
|
||||
"""
|
||||
return self / self.length
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__abs__(self)`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __abs__(self):
|
||||
return self.length
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self + other: Vector3 => Vector3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __add__(self, other: 'Vector3') -> 'Vector3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self + other: Point3 => Point3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __add__(self, other: 'Point3') -> 'Point3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self + other`
|
||||
|
||||
|
||||
|
||||
**説明**: V + P -> P
|
||||
|
||||
V + V -> V
|
||||
|
||||
**引数**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __add__(self, other):
|
||||
"""
|
||||
V + P -> P
|
||||
|
||||
V + V -> V
|
||||
Args:
|
||||
other:
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if isinstance(other, Vector3):
|
||||
return Vector3(self.x + other.x, self.y + other.y, self.z + other.z)
|
||||
elif isinstance(other, Point3):
|
||||
return Point3(self.x + other.x, self.y + other.y, self.z + other.z)
|
||||
else:
|
||||
raise TypeError(f"unsupported operand type(s) for +: 'Vector3' and '{type(other)}'")
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__eq__(self, other)`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两个向量是否相等。
|
||||
|
||||
**引数**:
|
||||
> - other:
|
||||
|
||||
**戻り値**: 是否相等
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```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>
|
||||
|
||||
### *method* `self + other: Point3 => Point3`
|
||||
|
||||
|
||||
|
||||
**説明**: P + V -> P
|
||||
|
||||
别去点那边实现了。
|
||||
:param other:
|
||||
:return:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __radd__(self, other: 'Point3') -> 'Point3':
|
||||
"""
|
||||
P + V -> P
|
||||
|
||||
别去点那边实现了。
|
||||
:param other:
|
||||
:return:
|
||||
"""
|
||||
return Point3(self.x + other.x, self.y + other.y, self.z + other.z)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self - other: Vector3 => Vector3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __sub__(self, other: 'Vector3') -> 'Vector3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self - other: Point3 => Point3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __sub__(self, other: 'Point3') -> 'Point3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self - other`
|
||||
|
||||
|
||||
|
||||
**説明**: V - P -> P
|
||||
|
||||
V - V -> V
|
||||
|
||||
**引数**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __sub__(self, other):
|
||||
"""
|
||||
V - P -> P
|
||||
|
||||
V - V -> V
|
||||
Args:
|
||||
other:
|
||||
Returns:
|
||||
"""
|
||||
if isinstance(other, Vector3):
|
||||
return Vector3(self.x - other.x, self.y - other.y, self.z - other.z)
|
||||
elif isinstance(other, Point3):
|
||||
return Point3(self.x - other.x, self.y - other.y, self.z - other.z)
|
||||
else:
|
||||
raise TypeError(f'unsupported operand type(s) for -: "Vector3" and "{type(other)}"')
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self - other: Point3`
|
||||
|
||||
|
||||
|
||||
**説明**: P - V -> P
|
||||
|
||||
**引数**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __rsub__(self, other: 'Point3'):
|
||||
"""
|
||||
P - V -> P
|
||||
Args:
|
||||
other:
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if isinstance(other, Point3):
|
||||
return Point3(other.x - self.x, other.y - self.y, other.z - self.z)
|
||||
else:
|
||||
raise TypeError(f"unsupported operand type(s) for -: '{type(other)}' and 'Vector3'")
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self * other: Vector3 => Vector3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __mul__(self, other: 'Vector3') -> 'Vector3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self * other: RealNumber => Vector3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __mul__(self, other: RealNumber) -> 'Vector3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self * other: int | float | Vector3 => Vector3`
|
||||
|
||||
|
||||
|
||||
**説明**: 数组运算 非点乘。点乘使用@,叉乘使用cross。
|
||||
|
||||
**引数**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __mul__(self, other: 'int | float | Vector3') -> 'Vector3':
|
||||
"""
|
||||
数组运算 非点乘。点乘使用@,叉乘使用cross。
|
||||
Args:
|
||||
other:
|
||||
|
||||
Returns:
|
||||
"""
|
||||
if isinstance(other, Vector3):
|
||||
return Vector3(self.x * other.x, self.y * other.y, self.z * other.z)
|
||||
elif isinstance(other, (float, int)):
|
||||
return Vector3(self.x * other, self.y * other, self.z * other)
|
||||
else:
|
||||
raise TypeError(f"unsupported operand type(s) for *: 'Vector3' and '{type(other)}'")
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self * other: RealNumber => Vector3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __rmul__(self, other: 'RealNumber') -> 'Vector3':
|
||||
return self.__mul__(other)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self @ other: Vector3 => RealNumber`
|
||||
|
||||
|
||||
|
||||
**説明**: 点乘。
|
||||
|
||||
**引数**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __matmul__(self, other: 'Vector3') -> 'RealNumber':
|
||||
"""
|
||||
点乘。
|
||||
Args:
|
||||
other:
|
||||
Returns:
|
||||
"""
|
||||
return self.x * other.x + self.y * other.y + self.z * other.z
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self / other: RealNumber => Vector3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __truediv__(self, other: RealNumber) -> 'Vector3':
|
||||
return Vector3(self.x / other, self.y / other, self.z / other)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `- self`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
def __neg__(self):
|
||||
return Vector3(-self.x, -self.y, -self.z)
|
||||
```
|
||||
</details>
|
||||
|
||||
### ***var*** `zero_vector3 = Vector3(0, 0, 0)`
|
||||
|
||||
- **タイプ**: `Vector3`
|
||||
|
||||
- **説明**: 零向量
|
||||
|
||||
### ***var*** `x_axis = Vector3(1, 0, 0)`
|
||||
|
||||
- **タイプ**: `Vector3`
|
||||
|
||||
- **説明**: x轴单位向量
|
||||
|
||||
### ***var*** `y_axis = Vector3(0, 1, 0)`
|
||||
|
||||
- **タイプ**: `Vector3`
|
||||
|
||||
- **説明**: y轴单位向量
|
||||
|
||||
### ***var*** `z_axis = Vector3(0, 0, 1)`
|
||||
|
||||
- **タイプ**: `Vector3`
|
||||
|
||||
- **説明**: z轴单位向量
|
||||
|
@ -1,3 +0,0 @@
|
||||
---
|
||||
title: mbcp.particle
|
||||
---
|
@ -1,3 +0,0 @@
|
||||
---
|
||||
title: mbcp.presets
|
||||
---
|
@ -1,43 +0,0 @@
|
||||
---
|
||||
title: mbcp.presets.model
|
||||
---
|
||||
### **class** `GeometricModels`
|
||||
### `@staticmethod`
|
||||
### *method* `sphere(radius: float, density: float)`
|
||||
|
||||
|
||||
|
||||
**説明**: 生成球体上的点集。
|
||||
|
||||
**引数**:
|
||||
> - radius:
|
||||
> - density:
|
||||
|
||||
**戻り値**: List[Point3]: 球体上的点集。
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>ソースコード</b> </summary>
|
||||
|
||||
```python
|
||||
@staticmethod
|
||||
def sphere(radius: float, density: float):
|
||||
"""
|
||||
生成球体上的点集。
|
||||
Args:
|
||||
radius:
|
||||
density:
|
||||
Returns:
|
||||
List[Point3]: 球体上的点集。
|
||||
"""
|
||||
area = 4 * np.pi * radius ** 2
|
||||
num = int(area * density)
|
||||
phi_list = np.arccos([clamp(-1 + (2.0 * _ - 1.0) / num, -1, 1) for _ in range(num)])
|
||||
theta_list = np.sqrt(num * np.pi) * phi_list
|
||||
x_array = radius * np.sin(phi_list) * np.cos(theta_list)
|
||||
y_array = radius * np.sin(phi_list) * np.sin(theta_list)
|
||||
z_array = radius * np.cos(phi_list)
|
||||
return [Point3(x_array[i], y_array[i], z_array[i]) for i in range(num)]
|
||||
```
|
||||
</details>
|
||||
|
@ -1,3 +0,0 @@
|
||||
---
|
||||
title: mbcp
|
||||
---
|
@ -1,399 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.angle
|
||||
---
|
||||
### **class** `Angle`
|
||||
### **class** `AnyAngle(Angle)`
|
||||
### *method* `__init__(self, value: float, is_radian: bool = False)`
|
||||
|
||||
|
||||
|
||||
**説明**: 任意角度。
|
||||
|
||||
**變數説明**:
|
||||
> - value: 角度或弧度值
|
||||
> - is_radian: 是否为弧度,默认为否
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, value: float, is_radian: bool=False):
|
||||
"""
|
||||
任意角度。
|
||||
Args:
|
||||
value: 角度或弧度值
|
||||
is_radian: 是否为弧度,默认为否
|
||||
"""
|
||||
if is_radian:
|
||||
self.radian = value
|
||||
else:
|
||||
self.radian = value * PI / 180
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `complementary(self) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**説明**: 余角:两角的和为90°。
|
||||
|
||||
**返回**: 余角
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def complementary(self) -> 'AnyAngle':
|
||||
"""
|
||||
余角:两角的和为90°。
|
||||
Returns:
|
||||
余角
|
||||
"""
|
||||
return AnyAngle(PI / 2 - self.minimum_positive.radian, is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `supplementary(self) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**説明**: 补角:两角的和为180°。
|
||||
|
||||
**返回**: 补角
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def supplementary(self) -> 'AnyAngle':
|
||||
"""
|
||||
补角:两角的和为180°。
|
||||
Returns:
|
||||
补角
|
||||
"""
|
||||
return AnyAngle(PI - self.minimum_positive.radian, is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `degree(self) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 角度。
|
||||
|
||||
**返回**: 弧度
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def degree(self) -> float:
|
||||
"""
|
||||
角度。
|
||||
Returns:
|
||||
弧度
|
||||
"""
|
||||
return self.radian * 180 / PI
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `minimum_positive(self) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**説明**: 最小正角。
|
||||
|
||||
**返回**: 最小正角度
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def minimum_positive(self) -> 'AnyAngle':
|
||||
"""
|
||||
最小正角。
|
||||
Returns:
|
||||
最小正角度
|
||||
"""
|
||||
return AnyAngle(self.radian % (2 * PI))
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `maximum_negative(self) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**説明**: 最大负角。
|
||||
|
||||
**返回**: 最大负角度
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def maximum_negative(self) -> 'AnyAngle':
|
||||
"""
|
||||
最大负角。
|
||||
Returns:
|
||||
最大负角度
|
||||
"""
|
||||
return AnyAngle(-self.radian % (2 * PI), is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `sin(self) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 正弦值。
|
||||
|
||||
**返回**: 正弦值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def sin(self) -> float:
|
||||
"""
|
||||
正弦值。
|
||||
Returns:
|
||||
正弦值
|
||||
"""
|
||||
return math.sin(self.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `cos(self) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 余弦值。
|
||||
|
||||
**返回**: 余弦值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def cos(self) -> float:
|
||||
"""
|
||||
余弦值。
|
||||
Returns:
|
||||
余弦值
|
||||
"""
|
||||
return math.cos(self.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `tan(self) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 正切值。
|
||||
|
||||
**返回**: 正切值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def tan(self) -> float:
|
||||
"""
|
||||
正切值。
|
||||
Returns:
|
||||
正切值
|
||||
"""
|
||||
return math.tan(self.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `cot(self) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 余切值。
|
||||
|
||||
**返回**: 余切值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def cot(self) -> float:
|
||||
"""
|
||||
余切值。
|
||||
Returns:
|
||||
余切值
|
||||
"""
|
||||
return 1 / math.tan(self.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `sec(self) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 正割值。
|
||||
|
||||
**返回**: 正割值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def sec(self) -> float:
|
||||
"""
|
||||
正割值。
|
||||
Returns:
|
||||
正割值
|
||||
"""
|
||||
return 1 / math.cos(self.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `csc(self) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 余割值。
|
||||
|
||||
**返回**: 余割值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def csc(self) -> float:
|
||||
"""
|
||||
余割值。
|
||||
Returns:
|
||||
余割值
|
||||
"""
|
||||
return 1 / math.sin(self.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self + other: AnyAngle => AnyAngle`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __add__(self, other: 'AnyAngle') -> 'AnyAngle':
|
||||
return AnyAngle(self.radian + other.radian, is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__eq__(self, other)`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __eq__(self, other):
|
||||
return approx(self.radian, other.radian)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self - other: AnyAngle => AnyAngle`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __sub__(self, other: 'AnyAngle') -> 'AnyAngle':
|
||||
return AnyAngle(self.radian - other.radian, is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self * other: float => AnyAngle`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __mul__(self, other: float) -> 'AnyAngle':
|
||||
return AnyAngle(self.radian * other, is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self / other: float => AnyAngle`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __truediv__(self, other: float) -> 'AnyAngle':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self / other: AnyAngle => float`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __truediv__(self, other: 'AnyAngle') -> float:
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self / other`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __truediv__(self, other):
|
||||
if isinstance(other, AnyAngle):
|
||||
return self.radian / other.radian
|
||||
return AnyAngle(self.radian / other, is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
@ -1,3 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.const
|
||||
---
|
@ -1,151 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.equation
|
||||
---
|
||||
### *func* `get_partial_derivative_func(func: MultiVarsFunc = EPSILON) -> MultiVarsFunc`
|
||||
|
||||
|
||||
|
||||
**説明**: 求N元函数一阶偏导函数。这玩意不太稳定,慎用。
|
||||
|
||||
**變數説明**:
|
||||
> - func: 函数
|
||||
> - var: 变量位置,可为整数(一阶偏导)或整数元组(高阶偏导)
|
||||
> - epsilon: 偏移量
|
||||
|
||||
**返回**: 偏导函数
|
||||
|
||||
**抛出**:
|
||||
> - ValueError 无效变量类型
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def get_partial_derivative_func(func: MultiVarsFunc, var: int | tuple[int, ...], epsilon: Number=EPSILON) -> MultiVarsFunc:
|
||||
"""
|
||||
求N元函数一阶偏导函数。这玩意不太稳定,慎用。
|
||||
Args:
|
||||
func: 函数
|
||||
var: 变量位置,可为整数(一阶偏导)或整数元组(高阶偏导)
|
||||
epsilon: 偏移量
|
||||
Returns:
|
||||
偏导函数
|
||||
Raises:
|
||||
ValueError: 无效变量类型
|
||||
"""
|
||||
if isinstance(var, int):
|
||||
|
||||
def partial_derivative_func(*args: Var) -> Var:
|
||||
args_list_plus = list(args)
|
||||
args_list_plus[var] += epsilon
|
||||
args_list_minus = list(args)
|
||||
args_list_minus[var] -= epsilon
|
||||
return (func(*args_list_plus) - func(*args_list_minus)) / (2 * epsilon)
|
||||
return partial_derivative_func
|
||||
elif isinstance(var, tuple):
|
||||
|
||||
def high_order_partial_derivative_func(*args: Var) -> Var:
|
||||
result_func = func
|
||||
for v in var:
|
||||
result_func = get_partial_derivative_func(result_func, v, epsilon)
|
||||
return result_func(*args)
|
||||
return high_order_partial_derivative_func
|
||||
else:
|
||||
raise ValueError('Invalid var type')
|
||||
```
|
||||
</details>
|
||||
|
||||
### *func* `partial_derivative_func() -> Var`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def partial_derivative_func(*args: Var) -> Var:
|
||||
args_list_plus = list(args)
|
||||
args_list_plus[var] += epsilon
|
||||
args_list_minus = list(args)
|
||||
args_list_minus[var] -= epsilon
|
||||
return (func(*args_list_plus) - func(*args_list_minus)) / (2 * epsilon)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *func* `high_order_partial_derivative_func() -> Var`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def high_order_partial_derivative_func(*args: Var) -> Var:
|
||||
result_func = func
|
||||
for v in var:
|
||||
result_func = get_partial_derivative_func(result_func, v, epsilon)
|
||||
return result_func(*args)
|
||||
```
|
||||
</details>
|
||||
|
||||
### **class** `CurveEquation`
|
||||
### *method* `__init__(self, x_func: OneVarFunc, y_func: OneVarFunc, z_func: OneVarFunc)`
|
||||
|
||||
|
||||
|
||||
**説明**: 曲线方程。
|
||||
|
||||
**變數説明**:
|
||||
> - x_func: x函数
|
||||
> - y_func: y函数
|
||||
> - z_func: z函数
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, x_func: OneVarFunc, y_func: OneVarFunc, z_func: OneVarFunc):
|
||||
"""
|
||||
曲线方程。
|
||||
Args:
|
||||
x_func: x函数
|
||||
y_func: y函数
|
||||
z_func: z函数
|
||||
"""
|
||||
self.x_func = x_func
|
||||
self.y_func = y_func
|
||||
self.z_func = z_func
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__call__(self) -> Point3 | tuple[Point3, ...]`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算曲线上的点。
|
||||
|
||||
**變數説明**:
|
||||
> - *t:
|
||||
> - 参数:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __call__(self, *t: Var) -> Point3 | tuple[Point3, ...]:
|
||||
"""
|
||||
计算曲线上的点。
|
||||
Args:
|
||||
*t:
|
||||
参数
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if len(t) == 1:
|
||||
return Point3(self.x_func(t[0]), self.y_func(t[0]), self.z_func(t[0]))
|
||||
else:
|
||||
return tuple([Point3(x, y, z) for x, y, z in zip(self.x_func(t), self.y_func(t), self.z_func(t))])
|
||||
```
|
||||
</details>
|
||||
|
@ -1,3 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math
|
||||
---
|
@ -1,530 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.line
|
||||
---
|
||||
### **class** `Line3`
|
||||
### *method* `__init__(self, point: Point3, direction: Vector3)`
|
||||
|
||||
|
||||
|
||||
**説明**: 三维空间中的直线。由一个点和一个方向向量确定。
|
||||
|
||||
**變數説明**:
|
||||
> - point: 直线上的一点
|
||||
> - direction: 直线的方向向量
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, point: 'Point3', direction: 'Vector3'):
|
||||
"""
|
||||
三维空间中的直线。由一个点和一个方向向量确定。
|
||||
Args:
|
||||
point: 直线上的一点
|
||||
direction: 直线的方向向量
|
||||
"""
|
||||
self.point = point
|
||||
self.direction = direction
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `approx(self, other: Line3, epsilon: float = APPROX) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两条直线是否近似相等。
|
||||
|
||||
**變數説明**:
|
||||
> - other: 另一条直线
|
||||
> - epsilon: 误差
|
||||
|
||||
**返回**: 是否近似相等
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def approx(self, other: 'Line3', epsilon: float=APPROX) -> bool:
|
||||
"""
|
||||
判断两条直线是否近似相等。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
epsilon: 误差
|
||||
Returns:
|
||||
是否近似相等
|
||||
"""
|
||||
return self.is_approx_parallel(other, epsilon) and (self.point - other.point).is_approx_parallel(self.direction, epsilon)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_angle(self, other: Line3) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算直线和直线之间的夹角。
|
||||
|
||||
**變數説明**:
|
||||
> - other: 另一条直线
|
||||
|
||||
**返回**: 夹角弧度
|
||||
|
||||
**抛出**:
|
||||
> - TypeError 不支持的类型
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_angle(self, other: 'Line3') -> 'AnyAngle':
|
||||
"""
|
||||
计算直线和直线之间的夹角。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
Returns:
|
||||
夹角弧度
|
||||
Raises:
|
||||
TypeError: 不支持的类型
|
||||
"""
|
||||
return self.direction.cal_angle(other.direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_distance(self, other: Line3 | Point3) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算直线和直线或点之间的距离。
|
||||
|
||||
**變數説明**:
|
||||
> - other: 平行直线或点
|
||||
|
||||
**返回**: 距离
|
||||
|
||||
**抛出**:
|
||||
> - TypeError 不支持的类型
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_distance(self, other: 'Line3 | Point3') -> float:
|
||||
"""
|
||||
计算直线和直线或点之间的距离。
|
||||
Args:
|
||||
other: 平行直线或点
|
||||
|
||||
Returns:
|
||||
距离
|
||||
Raises:
|
||||
TypeError: 不支持的类型
|
||||
"""
|
||||
if isinstance(other, Line3):
|
||||
if self == other:
|
||||
return 0
|
||||
elif self.is_parallel(other):
|
||||
return (other.point - self.point).cross(self.direction).length / self.direction.length
|
||||
elif not self.is_coplanar(other):
|
||||
return abs(self.direction.cross(other.direction) @ (self.point - other.point) / self.direction.cross(other.direction).length)
|
||||
else:
|
||||
return 0
|
||||
elif isinstance(other, Point3):
|
||||
return (other - self.point).cross(self.direction).length / self.direction.length
|
||||
else:
|
||||
raise TypeError('Unsupported type.')
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_intersection(self, other: Line3) -> Point3`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算两条直线的交点。
|
||||
|
||||
**變數説明**:
|
||||
> - other: 另一条直线
|
||||
|
||||
**返回**: 交点
|
||||
|
||||
**抛出**:
|
||||
> - ValueError 直线平行
|
||||
> - ValueError 直线不共面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_intersection(self, other: 'Line3') -> 'Point3':
|
||||
"""
|
||||
计算两条直线的交点。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
Returns:
|
||||
交点
|
||||
Raises:
|
||||
ValueError: 直线平行
|
||||
ValueError: 直线不共面
|
||||
"""
|
||||
if self.is_parallel(other):
|
||||
raise ValueError('Lines are parallel and do not intersect.')
|
||||
if not self.is_coplanar(other):
|
||||
raise ValueError('Lines are not coplanar and do not intersect.')
|
||||
return self.point + self.direction.cross(other.direction) @ other.direction.cross(self.point - other.point) / self.direction.cross(other.direction).length ** 2 * self.direction
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_perpendicular(self, point: Point3) -> Line3`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算直线经过指定点p的垂线。
|
||||
|
||||
**變數説明**:
|
||||
> - point: 指定点
|
||||
|
||||
**返回**: 垂线
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_perpendicular(self, point: 'Point3') -> 'Line3':
|
||||
"""
|
||||
计算直线经过指定点p的垂线。
|
||||
Args:
|
||||
point: 指定点
|
||||
Returns:
|
||||
垂线
|
||||
"""
|
||||
return Line3(point, self.direction.cross(point - self.point))
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `get_point(self, t: RealNumber) -> Point3`
|
||||
|
||||
|
||||
|
||||
**説明**: 获取直线上的点。同一条直线,但起始点和方向向量不同,则同一个t对应的点不同。
|
||||
|
||||
**變數説明**:
|
||||
> - t: 参数t
|
||||
|
||||
**返回**: 点
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def get_point(self, t: RealNumber) -> 'Point3':
|
||||
"""
|
||||
获取直线上的点。同一条直线,但起始点和方向向量不同,则同一个t对应的点不同。
|
||||
Args:
|
||||
t: 参数t
|
||||
Returns:
|
||||
点
|
||||
"""
|
||||
return self.point + t * self.direction
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `get_parametric_equations(self) -> tuple[OneSingleVarFunc, OneSingleVarFunc, OneSingleVarFunc]`
|
||||
|
||||
|
||||
|
||||
**説明**: 获取直线的参数方程。
|
||||
|
||||
**返回**: x(t), y(t), z(t)
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def get_parametric_equations(self) -> tuple[OneSingleVarFunc, OneSingleVarFunc, OneSingleVarFunc]:
|
||||
"""
|
||||
获取直线的参数方程。
|
||||
Returns:
|
||||
x(t), y(t), z(t)
|
||||
"""
|
||||
return (lambda t: self.point.x + self.direction.x * t, lambda t: self.point.y + self.direction.y * t, lambda t: self.point.z + self.direction.z * t)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_approx_parallel(self, other: Line3, epsilon: float = 1e-06) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两条直线是否近似平行。
|
||||
|
||||
**變數説明**:
|
||||
> - other: 另一条直线
|
||||
> - epsilon: 误差
|
||||
|
||||
**返回**: 是否近似平行
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def is_approx_parallel(self, other: 'Line3', epsilon: float=1e-06) -> bool:
|
||||
"""
|
||||
判断两条直线是否近似平行。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
epsilon: 误差
|
||||
Returns:
|
||||
是否近似平行
|
||||
"""
|
||||
return self.direction.is_approx_parallel(other.direction, epsilon)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_parallel(self, other: Line3) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两条直线是否平行。
|
||||
|
||||
**變數説明**:
|
||||
> - other: 另一条直线
|
||||
|
||||
**返回**: 是否平行
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def is_parallel(self, other: 'Line3') -> bool:
|
||||
"""
|
||||
判断两条直线是否平行。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
Returns:
|
||||
是否平行
|
||||
"""
|
||||
return self.direction.is_parallel(other.direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_collinear(self, other: Line3) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两条直线是否共线。
|
||||
|
||||
**變數説明**:
|
||||
> - other: 另一条直线
|
||||
|
||||
**返回**: 是否共线
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def is_collinear(self, other: 'Line3') -> bool:
|
||||
"""
|
||||
判断两条直线是否共线。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
Returns:
|
||||
是否共线
|
||||
"""
|
||||
return self.is_parallel(other) and (self.point - other.point).is_parallel(self.direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_point_on(self, point: Point3) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断点是否在直线上。
|
||||
|
||||
**變數説明**:
|
||||
> - point: 点
|
||||
|
||||
**返回**: 是否在直线上
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def is_point_on(self, point: 'Point3') -> bool:
|
||||
"""
|
||||
判断点是否在直线上。
|
||||
Args:
|
||||
point: 点
|
||||
Returns:
|
||||
是否在直线上
|
||||
"""
|
||||
return (point - self.point).is_parallel(self.direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_coplanar(self, other: Line3) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两条直线是否共面。
|
||||
充要条件:两直线方向向量的叉乘与两直线上任意一点的向量的点积为0。
|
||||
|
||||
**變數説明**:
|
||||
> - other: 另一条直线
|
||||
|
||||
**返回**: 是否共面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def is_coplanar(self, other: 'Line3') -> bool:
|
||||
"""
|
||||
判断两条直线是否共面。
|
||||
充要条件:两直线方向向量的叉乘与两直线上任意一点的向量的点积为0。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
Returns:
|
||||
是否共面
|
||||
"""
|
||||
return self.direction.cross(other.direction) @ (self.point - other.point) == 0
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `simplify(self)`
|
||||
|
||||
|
||||
|
||||
**説明**: 简化直线方程,等价相等。
|
||||
自体简化,不返回值。
|
||||
|
||||
按照可行性一次对x y z 化 0 处理,并对向量单位化
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def simplify(self):
|
||||
"""
|
||||
简化直线方程,等价相等。
|
||||
自体简化,不返回值。
|
||||
|
||||
按照可行性一次对x y z 化 0 处理,并对向量单位化
|
||||
"""
|
||||
self.direction.normalize()
|
||||
if self.direction.x == 0:
|
||||
self.point.x = 0
|
||||
if self.direction.y == 0:
|
||||
self.point.y = 0
|
||||
if self.direction.z == 0:
|
||||
self.point.z = 0
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@classmethod`
|
||||
### *method* `from_two_points(cls, p1: Point3, p2: Point3) -> Line3`
|
||||
|
||||
|
||||
|
||||
**説明**: 工厂函数 由两点构造直线。
|
||||
|
||||
**變數説明**:
|
||||
> - p1: 点1
|
||||
> - p2: 点2
|
||||
|
||||
**返回**: 直线
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@classmethod
|
||||
def from_two_points(cls, p1: 'Point3', p2: 'Point3') -> 'Line3':
|
||||
"""
|
||||
工厂函数 由两点构造直线。
|
||||
Args:
|
||||
p1: 点1
|
||||
p2: 点2
|
||||
Returns:
|
||||
直线
|
||||
"""
|
||||
direction = p2 - p1
|
||||
return cls(p1, direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__and__(self, other: Line3) -> Line3 | Point3 | None`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算两条直线点集合的交集。重合线返回自身,平行线返回None,交线返回交点。
|
||||
|
||||
**變數説明**:
|
||||
> - other: 另一条直线
|
||||
|
||||
**返回**: 交点
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __and__(self, other: 'Line3') -> 'Line3 | Point3 | None':
|
||||
"""
|
||||
计算两条直线点集合的交集。重合线返回自身,平行线返回None,交线返回交点。
|
||||
Args:
|
||||
other: 另一条直线
|
||||
Returns:
|
||||
交点
|
||||
"""
|
||||
if self.is_collinear(other):
|
||||
return self
|
||||
elif self.is_parallel(other) or not self.is_coplanar(other):
|
||||
return None
|
||||
else:
|
||||
return self.cal_intersection(other)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__eq__(self, other) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两条直线是否等价。
|
||||
|
||||
v1 // v2 ∧ (p1 - p2) // v1
|
||||
|
||||
**變數説明**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __eq__(self, other) -> bool:
|
||||
"""
|
||||
判断两条直线是否等价。
|
||||
|
||||
v1 // v2 ∧ (p1 - p2) // v1
|
||||
Args:
|
||||
other:
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
return self.direction.is_parallel(other.direction) and (self.point - other.point).is_parallel(self.direction)
|
||||
```
|
||||
</details>
|
||||
|
@ -1,63 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.mp_math_typing
|
||||
---
|
||||
### ***var*** `RealNumber = int | float`
|
||||
|
||||
- **類型**: `TypeAlias`
|
||||
|
||||
### ***var*** `Number = RealNumber | complex`
|
||||
|
||||
- **類型**: `TypeAlias`
|
||||
|
||||
### ***var*** `Var = SingleVar | ArrayVar`
|
||||
|
||||
- **類型**: `TypeAlias`
|
||||
|
||||
### ***var*** `OneSingleVarFunc = Callable[[SingleVar], SingleVar]`
|
||||
|
||||
- **類型**: `TypeAlias`
|
||||
|
||||
### ***var*** `OneArrayFunc = Callable[[ArrayVar], ArrayVar]`
|
||||
|
||||
- **類型**: `TypeAlias`
|
||||
|
||||
### ***var*** `OneVarFunc = OneSingleVarFunc | OneArrayFunc`
|
||||
|
||||
- **類型**: `TypeAlias`
|
||||
|
||||
### ***var*** `TwoSingleVarsFunc = Callable[[SingleVar, SingleVar], SingleVar]`
|
||||
|
||||
- **類型**: `TypeAlias`
|
||||
|
||||
### ***var*** `TwoArraysFunc = Callable[[ArrayVar, ArrayVar], ArrayVar]`
|
||||
|
||||
- **類型**: `TypeAlias`
|
||||
|
||||
### ***var*** `TwoVarsFunc = TwoSingleVarsFunc | TwoArraysFunc`
|
||||
|
||||
- **類型**: `TypeAlias`
|
||||
|
||||
### ***var*** `ThreeSingleVarsFunc = Callable[[SingleVar, SingleVar, SingleVar], SingleVar]`
|
||||
|
||||
- **類型**: `TypeAlias`
|
||||
|
||||
### ***var*** `ThreeArraysFunc = Callable[[ArrayVar, ArrayVar, ArrayVar], ArrayVar]`
|
||||
|
||||
- **類型**: `TypeAlias`
|
||||
|
||||
### ***var*** `ThreeVarsFunc = ThreeSingleVarsFunc | ThreeArraysFunc`
|
||||
|
||||
- **類型**: `TypeAlias`
|
||||
|
||||
### ***var*** `MultiSingleVarsFunc = Callable[..., SingleVar]`
|
||||
|
||||
- **類型**: `TypeAlias`
|
||||
|
||||
### ***var*** `MultiArraysFunc = Callable[..., ArrayVar]`
|
||||
|
||||
- **類型**: `TypeAlias`
|
||||
|
||||
### ***var*** `MultiVarsFunc = MultiSingleVarsFunc | MultiArraysFunc`
|
||||
|
||||
- **類型**: `TypeAlias`
|
||||
|
@ -1,542 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.plane
|
||||
---
|
||||
### **class** `Plane3`
|
||||
### *method* `__init__(self, a: float, b: float, c: float, d: float)`
|
||||
|
||||
|
||||
|
||||
**説明**: 平面方程:ax + by + cz + d = 0
|
||||
|
||||
**變數説明**:
|
||||
> - a: x系数
|
||||
> - b: y系数
|
||||
> - c: z系数
|
||||
> - d: 常数项
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, a: float, b: float, c: float, d: float):
|
||||
"""
|
||||
平面方程:ax + by + cz + d = 0
|
||||
Args:
|
||||
a: x系数
|
||||
b: y系数
|
||||
c: z系数
|
||||
d: 常数项
|
||||
"""
|
||||
self.a = a
|
||||
self.b = b
|
||||
self.c = c
|
||||
self.d = d
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `approx(self, other: Plane3) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两个平面是否近似相等。
|
||||
|
||||
**變數説明**:
|
||||
> - other: 另一个平面
|
||||
|
||||
**返回**: 是否近似相等
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def approx(self, other: 'Plane3') -> bool:
|
||||
"""
|
||||
判断两个平面是否近似相等。
|
||||
Args:
|
||||
other: 另一个平面
|
||||
Returns:
|
||||
是否近似相等
|
||||
"""
|
||||
if self.a != 0:
|
||||
k = other.a / self.a
|
||||
return approx(other.b, self.b * k) and approx(other.c, self.c * k) and approx(other.d, self.d * k)
|
||||
elif self.b != 0:
|
||||
k = other.b / self.b
|
||||
return approx(other.a, self.a * k) and approx(other.c, self.c * k) and approx(other.d, self.d * k)
|
||||
elif self.c != 0:
|
||||
k = other.c / self.c
|
||||
return approx(other.a, self.a * k) and approx(other.b, self.b * k) and approx(other.d, self.d * k)
|
||||
else:
|
||||
return False
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_angle(self, other: Line3 | Plane3) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算平面与平面之间的夹角。
|
||||
|
||||
**變數説明**:
|
||||
> - other: 另一个平面
|
||||
|
||||
**返回**: 夹角弧度
|
||||
|
||||
**抛出**:
|
||||
> - TypeError 不支持的类型
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_angle(self, other: 'Line3 | Plane3') -> 'AnyAngle':
|
||||
"""
|
||||
计算平面与平面之间的夹角。
|
||||
Args:
|
||||
other: 另一个平面
|
||||
Returns:
|
||||
夹角弧度
|
||||
Raises:
|
||||
TypeError: 不支持的类型
|
||||
"""
|
||||
if isinstance(other, Line3):
|
||||
return self.normal.cal_angle(other.direction).complementary
|
||||
elif isinstance(other, Plane3):
|
||||
return AnyAngle(math.acos(self.normal @ other.normal / (self.normal.length * other.normal.length)), is_radian=True)
|
||||
else:
|
||||
raise TypeError(f'Unsupported type: {type(other)}')
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_distance(self, other: Plane3 | Point3) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算平面与平面或点之间的距离。
|
||||
|
||||
**變數説明**:
|
||||
> - other: 另一个平面或点
|
||||
|
||||
**返回**: 距离
|
||||
|
||||
**抛出**:
|
||||
> - TypeError 不支持的类型
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_distance(self, other: 'Plane3 | Point3') -> float:
|
||||
"""
|
||||
计算平面与平面或点之间的距离。
|
||||
Args:
|
||||
other: 另一个平面或点
|
||||
Returns:
|
||||
距离
|
||||
Raises:
|
||||
TypeError: 不支持的类型
|
||||
"""
|
||||
if isinstance(other, Plane3):
|
||||
return 0
|
||||
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:
|
||||
raise TypeError(f'Unsupported type: {type(other)}')
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_intersection_line3(self, other: Plane3) -> Line3`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算两平面的交线。
|
||||
|
||||
**變數説明**:
|
||||
> - other: 另一个平面
|
||||
|
||||
**返回**: 两平面的交线
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_intersection_line3(self, other: 'Plane3') -> 'Line3':
|
||||
"""
|
||||
计算两平面的交线。
|
||||
Args:
|
||||
other: 另一个平面
|
||||
Returns:
|
||||
两平面的交线
|
||||
Raises:
|
||||
"""
|
||||
if self.normal.is_parallel(other.normal):
|
||||
raise ValueError('Planes are parallel and have no intersection.')
|
||||
direction = self.normal.cross(other.normal)
|
||||
x, y, z = (0, 0, 0)
|
||||
if self.a != 0 and other.a != 0:
|
||||
A = np.array([[self.b, self.c], [other.b, other.c]])
|
||||
B = np.array([-self.d, -other.d])
|
||||
y, z = np.linalg.solve(A, B)
|
||||
elif self.b != 0 and other.b != 0:
|
||||
A = np.array([[self.a, self.c], [other.a, other.c]])
|
||||
B = np.array([-self.d, -other.d])
|
||||
x, z = np.linalg.solve(A, B)
|
||||
elif self.c != 0 and other.c != 0:
|
||||
A = np.array([[self.a, self.b], [other.a, other.b]])
|
||||
B = np.array([-self.d, -other.d])
|
||||
x, y = np.linalg.solve(A, B)
|
||||
return Line3(Point3(x, y, z), direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_intersection_point3(self, other: Line3) -> Point3`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算平面与直线的交点。
|
||||
|
||||
**變數説明**:
|
||||
> - other: 不与平面平行或在平面上的直线
|
||||
|
||||
**返回**: 交点
|
||||
|
||||
**抛出**:
|
||||
> - ValueError 平面与直线平行或重合
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_intersection_point3(self, other: 'Line3') -> 'Point3':
|
||||
"""
|
||||
计算平面与直线的交点。
|
||||
Args:
|
||||
other: 不与平面平行或在平面上的直线
|
||||
Returns:
|
||||
交点
|
||||
Raises:
|
||||
ValueError: 平面与直线平行或重合
|
||||
"""
|
||||
if self.normal @ other.direction == 0:
|
||||
raise ValueError('The plane and the line are parallel or coincident.')
|
||||
x, y, z = other.get_parametric_equations()
|
||||
t = -(self.a * other.point.x + self.b * other.point.y + self.c * other.point.z + self.d) / (self.a * other.direction.x + self.b * other.direction.y + self.c * other.direction.z)
|
||||
return Point3(x(t), y(t), z(t))
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cal_parallel_plane3(self, point: Point3) -> Plane3`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算平行于该平面且过指定点的平面。
|
||||
|
||||
**變數説明**:
|
||||
> - point: 指定点
|
||||
|
||||
**返回**: 所求平面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_parallel_plane3(self, point: 'Point3') -> 'Plane3':
|
||||
"""
|
||||
计算平行于该平面且过指定点的平面。
|
||||
Args:
|
||||
point: 指定点
|
||||
Returns:
|
||||
所求平面
|
||||
"""
|
||||
return Plane3.from_point_and_normal(point, self.normal)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_parallel(self, other: Plane3) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两个平面是否平行。
|
||||
|
||||
**變數説明**:
|
||||
> - other: 另一个平面
|
||||
|
||||
**返回**: 是否平行
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def is_parallel(self, other: 'Plane3') -> bool:
|
||||
"""
|
||||
判断两个平面是否平行。
|
||||
Args:
|
||||
other: 另一个平面
|
||||
Returns:
|
||||
是否平行
|
||||
"""
|
||||
return self.normal.is_parallel(other.normal)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `normal(self) -> Vector3`
|
||||
|
||||
|
||||
|
||||
**説明**: 平面的法向量。
|
||||
|
||||
**返回**: 法向量
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def normal(self) -> 'Vector3':
|
||||
"""
|
||||
平面的法向量。
|
||||
Returns:
|
||||
法向量
|
||||
"""
|
||||
return Vector3(self.a, self.b, self.c)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@classmethod`
|
||||
### *method* `from_point_and_normal(cls, point: Point3, normal: Vector3) -> Plane3`
|
||||
|
||||
|
||||
|
||||
**説明**: 工厂函数 由点和法向量构造平面(点法式构造)。
|
||||
|
||||
**變數説明**:
|
||||
> - point: 平面上的一点
|
||||
> - normal: 法向量
|
||||
|
||||
**返回**: 平面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@classmethod
|
||||
def from_point_and_normal(cls, point: 'Point3', normal: 'Vector3') -> 'Plane3':
|
||||
"""
|
||||
工厂函数 由点和法向量构造平面(点法式构造)。
|
||||
Args:
|
||||
point: 平面上的一点
|
||||
normal: 法向量
|
||||
Returns:
|
||||
平面
|
||||
"""
|
||||
a, b, c = (normal.x, normal.y, normal.z)
|
||||
d = -a * point.x - b * point.y - c * point.z
|
||||
return cls(a, b, c, d)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@classmethod`
|
||||
### *method* `from_three_points(cls, p1: Point3, p2: Point3, p3: Point3) -> Plane3`
|
||||
|
||||
|
||||
|
||||
**説明**: 工厂函数 由三点构造平面。
|
||||
|
||||
**變數説明**:
|
||||
> - p1: 点1
|
||||
> - p2: 点2
|
||||
> - p3: 点3
|
||||
|
||||
**返回**: 平面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@classmethod
|
||||
def from_three_points(cls, p1: 'Point3', p2: 'Point3', p3: 'Point3') -> 'Plane3':
|
||||
"""
|
||||
工厂函数 由三点构造平面。
|
||||
Args:
|
||||
p1: 点1
|
||||
p2: 点2
|
||||
p3: 点3
|
||||
Returns:
|
||||
平面
|
||||
"""
|
||||
v1 = p2 - p1
|
||||
v2 = p3 - p1
|
||||
normal = v1.cross(v2)
|
||||
return cls.from_point_and_normal(p1, normal)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@classmethod`
|
||||
### *method* `from_two_lines(cls, l1: Line3, l2: Line3) -> Plane3`
|
||||
|
||||
|
||||
|
||||
**説明**: 工厂函数 由两直线构造平面。
|
||||
|
||||
**變數説明**:
|
||||
> - l1: 直线1
|
||||
> - l2: 直线2
|
||||
|
||||
**返回**: 平面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@classmethod
|
||||
def from_two_lines(cls, l1: 'Line3', l2: 'Line3') -> 'Plane3':
|
||||
"""
|
||||
工厂函数 由两直线构造平面。
|
||||
Args:
|
||||
l1: 直线1
|
||||
l2: 直线2
|
||||
Returns:
|
||||
平面
|
||||
"""
|
||||
v1 = l1.direction
|
||||
v2 = l2.point - l1.point
|
||||
if v2 == zero_vector3:
|
||||
v2 = l2.get_point(1) - l1.point
|
||||
return cls.from_point_and_normal(l1.point, v1.cross(v2))
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@classmethod`
|
||||
### *method* `from_point_and_line(cls, point: Point3, line: Line3) -> Plane3`
|
||||
|
||||
|
||||
|
||||
**説明**: 工厂函数 由点和直线构造平面。
|
||||
|
||||
**變數説明**:
|
||||
> - point: 面上一点
|
||||
> - line: 面上直线,不包含点
|
||||
|
||||
**返回**: 平面
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@classmethod
|
||||
def from_point_and_line(cls, point: 'Point3', line: 'Line3') -> 'Plane3':
|
||||
"""
|
||||
工厂函数 由点和直线构造平面。
|
||||
Args:
|
||||
point: 面上一点
|
||||
line: 面上直线,不包含点
|
||||
Returns:
|
||||
平面
|
||||
"""
|
||||
return cls.from_point_and_normal(point, line.direction)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `__and__(self, other: Line3) -> Point3 | None`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __and__(self, other: 'Line3') -> 'Point3 | None':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `__and__(self, other: Plane3) -> Line3 | None`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __and__(self, other: 'Plane3') -> 'Line3 | None':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__and__(self, other)`
|
||||
|
||||
|
||||
|
||||
**説明**: 取两平面的交集(人话:交线)
|
||||
|
||||
**變數説明**:
|
||||
> - other:
|
||||
|
||||
**返回**: 不平行平面的交线,平面平行返回None
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __and__(self, other):
|
||||
"""
|
||||
取两平面的交集(人话:交线)
|
||||
Args:
|
||||
other:
|
||||
Returns:
|
||||
不平行平面的交线,平面平行返回None
|
||||
"""
|
||||
if isinstance(other, Plane3):
|
||||
if self.normal.is_parallel(other.normal):
|
||||
return None
|
||||
return self.cal_intersection_line3(other)
|
||||
elif isinstance(other, Line3):
|
||||
if self.normal @ other.direction == 0:
|
||||
return None
|
||||
return self.cal_intersection_point3(other)
|
||||
else:
|
||||
raise TypeError(f"unsupported operand type(s) for &: 'Plane3' and '{type(other)}'")
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__eq__(self, other) -> bool`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __eq__(self, other) -> bool:
|
||||
return self.approx(other)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__rand__(self, other: Line3) -> Point3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __rand__(self, other: 'Line3') -> 'Point3':
|
||||
return self.cal_intersection_point3(other)
|
||||
```
|
||||
</details>
|
||||
|
@ -1,176 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.point
|
||||
---
|
||||
### **class** `Point3`
|
||||
### *method* `__init__(self, x: float, y: float, z: float)`
|
||||
|
||||
|
||||
|
||||
**説明**: 笛卡尔坐标系中的点。
|
||||
|
||||
**變數説明**:
|
||||
> - x: x 坐标
|
||||
> - y: y 坐标
|
||||
> - z: z 坐标
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```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>
|
||||
|
||||
### *method* `approx(self, other: Point3, epsilon: float = APPROX) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两个点是否近似相等。
|
||||
|
||||
**變數説明**:
|
||||
> - other:
|
||||
> - epsilon:
|
||||
|
||||
**返回**: 是否近似相等
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```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>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self + other: Vector3 => Point3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __add__(self, other: 'Vector3') -> 'Point3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self + other: Point3 => Point3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __add__(self, other: 'Point3') -> 'Point3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self + other`
|
||||
|
||||
|
||||
|
||||
**説明**: P + V -> P
|
||||
P + P -> P
|
||||
|
||||
**變數説明**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```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>
|
||||
|
||||
### *method* `__eq__(self, other)`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两个点是否相等。
|
||||
|
||||
**變數説明**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```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>
|
||||
|
||||
### *method* `self - other: Point3 => Vector3`
|
||||
|
||||
|
||||
|
||||
**説明**: P - P -> V
|
||||
|
||||
P - V -> P 已在 :class:`Vector3` 中实现
|
||||
|
||||
**變數説明**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```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>
|
||||
|
@ -1,34 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.segment
|
||||
---
|
||||
### **class** `Segment3`
|
||||
### *method* `__init__(self, p1: Point3, p2: Point3)`
|
||||
|
||||
|
||||
|
||||
**説明**: 三维空间中的线段。
|
||||
:param p1:
|
||||
:param p2:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, p1: 'Point3', p2: 'Point3'):
|
||||
"""
|
||||
三维空间中的线段。
|
||||
:param p1:
|
||||
:param p2:
|
||||
"""
|
||||
self.p1 = p1
|
||||
self.p2 = p2
|
||||
'方向向量'
|
||||
self.direction = self.p2 - self.p1
|
||||
'长度'
|
||||
self.length = self.direction.length
|
||||
'中心点'
|
||||
self.midpoint = Point3((self.p1.x + self.p2.x) / 2, (self.p1.y + self.p2.y) / 2, (self.p1.z + self.p2.z) / 2)
|
||||
```
|
||||
</details>
|
||||
|
@ -1,200 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.utils
|
||||
---
|
||||
### *func* `clamp() -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 区间限定函数
|
||||
|
||||
**變數説明**:
|
||||
> - x: 待限定的值
|
||||
> - min_: 最小值
|
||||
> - max_: 最大值
|
||||
|
||||
**返回**: 限制后的值
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def clamp(x: float, min_: float, max_: float) -> float:
|
||||
"""
|
||||
区间限定函数
|
||||
Args:
|
||||
x: 待限定的值
|
||||
min_: 最小值
|
||||
max_: 最大值
|
||||
|
||||
Returns:
|
||||
限制后的值
|
||||
"""
|
||||
return max(min(x, max_), min_)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *func* `approx(x: float = 0.0, y: float = APPROX) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两个数是否近似相等。或包装一个实数,用于判断是否近似于0。
|
||||
|
||||
**變數説明**:
|
||||
> - x: 数1
|
||||
> - y: 数2
|
||||
> - epsilon: 误差
|
||||
|
||||
**返回**: 是否近似相等
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def approx(x: float, y: float=0.0, epsilon: float=APPROX) -> bool:
|
||||
"""
|
||||
判断两个数是否近似相等。或包装一个实数,用于判断是否近似于0。
|
||||
Args:
|
||||
x: 数1
|
||||
y: 数2
|
||||
epsilon: 误差
|
||||
Returns:
|
||||
是否近似相等
|
||||
"""
|
||||
return abs(x - y) < epsilon
|
||||
```
|
||||
</details>
|
||||
|
||||
### *func* `sign(x: float = False) -> str`
|
||||
|
||||
|
||||
|
||||
**説明**: 获取数的符号。
|
||||
|
||||
**變數説明**:
|
||||
> - x: 数
|
||||
> - only_neg: 是否只返回负数的符号
|
||||
|
||||
**返回**: 符号 + - ""
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def sign(x: float, only_neg: bool=False) -> str:
|
||||
"""获取数的符号。
|
||||
Args:
|
||||
x: 数
|
||||
only_neg: 是否只返回负数的符号
|
||||
Returns:
|
||||
符号 + - ""
|
||||
"""
|
||||
if x > 0:
|
||||
return '+' if not only_neg else ''
|
||||
elif x < 0:
|
||||
return '-'
|
||||
else:
|
||||
return ''
|
||||
```
|
||||
</details>
|
||||
|
||||
### *func* `sign_format(x: float = False) -> str`
|
||||
|
||||
|
||||
|
||||
**説明**: 格式化符号数
|
||||
-1 -> -1
|
||||
1 -> +1
|
||||
0 -> ""
|
||||
|
||||
**變數説明**:
|
||||
> - x: 数
|
||||
> - only_neg: 是否只返回负数的符号
|
||||
|
||||
**返回**: 符号 + - ""
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def sign_format(x: float, only_neg: bool=False) -> str:
|
||||
"""格式化符号数
|
||||
-1 -> -1
|
||||
1 -> +1
|
||||
0 -> ""
|
||||
Args:
|
||||
x: 数
|
||||
only_neg: 是否只返回负数的符号
|
||||
Returns:
|
||||
符号 + - ""
|
||||
"""
|
||||
if x > 0:
|
||||
return f'+{x}' if not only_neg else f'{x}'
|
||||
elif x < 0:
|
||||
return f'-{abs(x)}'
|
||||
else:
|
||||
return ''
|
||||
```
|
||||
</details>
|
||||
|
||||
### **class** `Approx`
|
||||
### *method* `__init__(self, value: RealNumber)`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, value: RealNumber):
|
||||
self.value = value
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__eq__(self, other)`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __eq__(self, other):
|
||||
if isinstance(self.value, (float, int)):
|
||||
if isinstance(other, (float, int)):
|
||||
return abs(self.value - other) < APPROX
|
||||
else:
|
||||
self.raise_type_error(other)
|
||||
elif isinstance(self.value, Vector3):
|
||||
if isinstance(other, (Vector3, Point3, Plane3, Line3)):
|
||||
return all([approx(self.value.x, other.x), approx(self.value.y, other.y), approx(self.value.z, other.z)])
|
||||
else:
|
||||
self.raise_type_error(other)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `raise_type_error(self, other)`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def raise_type_error(self, other):
|
||||
raise TypeError(f'Unsupported type: {type(self.value)} and {type(other)}')
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__ne__(self, other)`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
```
|
||||
</details>
|
||||
|
@ -1,656 +0,0 @@
|
||||
---
|
||||
title: mbcp.mp_math.vector
|
||||
---
|
||||
### **class** `Vector3`
|
||||
### *method* `__init__(self, x: float, y: float, z: float)`
|
||||
|
||||
|
||||
|
||||
**説明**: 3维向量
|
||||
|
||||
**變數説明**:
|
||||
> - x: x轴分量
|
||||
> - y: y轴分量
|
||||
> - z: z轴分量
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __init__(self, x: float, y: float, z: float):
|
||||
"""
|
||||
3维向量
|
||||
Args:
|
||||
x: x轴分量
|
||||
y: y轴分量
|
||||
z: z轴分量
|
||||
"""
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.z = z
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `approx(self, other: Vector3, epsilon: float = APPROX) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两个向量是否近似相等。
|
||||
|
||||
**變數説明**:
|
||||
> - other:
|
||||
> - epsilon:
|
||||
|
||||
**返回**: 是否近似相等
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def approx(self, other: 'Vector3', 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>
|
||||
|
||||
### *method* `cal_angle(self, other: Vector3) -> AnyAngle`
|
||||
|
||||
|
||||
|
||||
**説明**: 计算两个向量之间的夹角。
|
||||
|
||||
**變數説明**:
|
||||
> - other: 另一个向量
|
||||
|
||||
**返回**: 夹角
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def cal_angle(self, other: 'Vector3') -> 'AnyAngle':
|
||||
"""
|
||||
计算两个向量之间的夹角。
|
||||
Args:
|
||||
other: 另一个向量
|
||||
Returns:
|
||||
夹角
|
||||
"""
|
||||
return AnyAngle(math.acos(self @ other / (self.length * other.length)), is_radian=True)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `cross(self, other: Vector3) -> Vector3`
|
||||
|
||||
|
||||
|
||||
**説明**: 向量积 叉乘:v1 cross v2 -> v3
|
||||
|
||||
叉乘为0,则两向量平行。
|
||||
其余结果的模为平行四边形的面积。
|
||||
|
||||
|
||||
**變數説明**:
|
||||
> - other:
|
||||
|
||||
**返回**: 行列式的结果
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def cross(self, other: 'Vector3') -> 'Vector3':
|
||||
"""
|
||||
向量积 叉乘:v1 cross v2 -> v3
|
||||
|
||||
叉乘为0,则两向量平行。
|
||||
其余结果的模为平行四边形的面积。
|
||||
|
||||
返回如下行列式的结果:
|
||||
|
||||
``i j k``
|
||||
|
||||
``x1 y1 z1``
|
||||
|
||||
``x2 y2 z2``
|
||||
|
||||
Args:
|
||||
other:
|
||||
Returns:
|
||||
行列式的结果
|
||||
"""
|
||||
return Vector3(self.y * other.z - self.z * other.y, self.z * other.x - self.x * other.z, self.x * other.y - self.y * other.x)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_approx_parallel(self, other: Vector3, epsilon: float = APPROX) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两个向量是否近似平行。
|
||||
|
||||
**變數説明**:
|
||||
> - other: 另一个向量
|
||||
> - epsilon: 允许的误差
|
||||
|
||||
**返回**: 是否近似平行
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def is_approx_parallel(self, other: 'Vector3', epsilon: float=APPROX) -> bool:
|
||||
"""
|
||||
判断两个向量是否近似平行。
|
||||
Args:
|
||||
other: 另一个向量
|
||||
epsilon: 允许的误差
|
||||
Returns:
|
||||
是否近似平行
|
||||
"""
|
||||
return self.cross(other).length < epsilon
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `is_parallel(self, other: Vector3) -> bool`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两个向量是否平行。
|
||||
|
||||
**變數説明**:
|
||||
> - other: 另一个向量
|
||||
|
||||
**返回**: 是否平行
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def is_parallel(self, other: 'Vector3') -> bool:
|
||||
"""
|
||||
判断两个向量是否平行。
|
||||
Args:
|
||||
other: 另一个向量
|
||||
Returns:
|
||||
是否平行
|
||||
"""
|
||||
return self.cross(other).approx(zero_vector3)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `normalize(self)`
|
||||
|
||||
|
||||
|
||||
**説明**: 将向量归一化。
|
||||
|
||||
自体归一化,不返回值。
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def normalize(self):
|
||||
"""
|
||||
将向量归一化。
|
||||
|
||||
自体归一化,不返回值。
|
||||
"""
|
||||
length = self.length
|
||||
self.x /= length
|
||||
self.y /= length
|
||||
self.z /= length
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `np_array(self) -> np.ndarray`
|
||||
|
||||
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def np_array(self) -> 'np.ndarray':
|
||||
"""
|
||||
返回numpy数组
|
||||
Returns:
|
||||
"""
|
||||
return np.array([self.x, self.y, self.z])
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `length(self) -> float`
|
||||
|
||||
|
||||
|
||||
**説明**: 向量的模。
|
||||
|
||||
**返回**: 模
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def length(self) -> float:
|
||||
"""
|
||||
向量的模。
|
||||
Returns:
|
||||
模
|
||||
"""
|
||||
return math.sqrt(self.x ** 2 + self.y ** 2 + self.z ** 2)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@property`
|
||||
### *method* `unit(self) -> Vector3`
|
||||
|
||||
|
||||
|
||||
**説明**: 获取该向量的单位向量。
|
||||
|
||||
**返回**: 单位向量
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@property
|
||||
def unit(self) -> 'Vector3':
|
||||
"""
|
||||
获取该向量的单位向量。
|
||||
Returns:
|
||||
单位向量
|
||||
"""
|
||||
return self / self.length
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__abs__(self)`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __abs__(self):
|
||||
return self.length
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self + other: Vector3 => Vector3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __add__(self, other: 'Vector3') -> 'Vector3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self + other: Point3 => Point3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __add__(self, other: 'Point3') -> 'Point3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self + other`
|
||||
|
||||
|
||||
|
||||
**説明**: V + P -> P
|
||||
|
||||
V + V -> V
|
||||
|
||||
**變數説明**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __add__(self, other):
|
||||
"""
|
||||
V + P -> P
|
||||
|
||||
V + V -> V
|
||||
Args:
|
||||
other:
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if isinstance(other, Vector3):
|
||||
return Vector3(self.x + other.x, self.y + other.y, self.z + other.z)
|
||||
elif isinstance(other, Point3):
|
||||
return Point3(self.x + other.x, self.y + other.y, self.z + other.z)
|
||||
else:
|
||||
raise TypeError(f"unsupported operand type(s) for +: 'Vector3' and '{type(other)}'")
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `__eq__(self, other)`
|
||||
|
||||
|
||||
|
||||
**説明**: 判断两个向量是否相等。
|
||||
|
||||
**變數説明**:
|
||||
> - other:
|
||||
|
||||
**返回**: 是否相等
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```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>
|
||||
|
||||
### *method* `self + other: Point3 => Point3`
|
||||
|
||||
|
||||
|
||||
**説明**: P + V -> P
|
||||
|
||||
别去点那边实现了。
|
||||
:param other:
|
||||
:return:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __radd__(self, other: 'Point3') -> 'Point3':
|
||||
"""
|
||||
P + V -> P
|
||||
|
||||
别去点那边实现了。
|
||||
:param other:
|
||||
:return:
|
||||
"""
|
||||
return Point3(self.x + other.x, self.y + other.y, self.z + other.z)
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self - other: Vector3 => Vector3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __sub__(self, other: 'Vector3') -> 'Vector3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self - other: Point3 => Point3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __sub__(self, other: 'Point3') -> 'Point3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self - other`
|
||||
|
||||
|
||||
|
||||
**説明**: V - P -> P
|
||||
|
||||
V - V -> V
|
||||
|
||||
**變數説明**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __sub__(self, other):
|
||||
"""
|
||||
V - P -> P
|
||||
|
||||
V - V -> V
|
||||
Args:
|
||||
other:
|
||||
Returns:
|
||||
"""
|
||||
if isinstance(other, Vector3):
|
||||
return Vector3(self.x - other.x, self.y - other.y, self.z - other.z)
|
||||
elif isinstance(other, Point3):
|
||||
return Point3(self.x - other.x, self.y - other.y, self.z - other.z)
|
||||
else:
|
||||
raise TypeError(f'unsupported operand type(s) for -: "Vector3" and "{type(other)}"')
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self - other: Point3`
|
||||
|
||||
|
||||
|
||||
**説明**: P - V -> P
|
||||
|
||||
**變數説明**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __rsub__(self, other: 'Point3'):
|
||||
"""
|
||||
P - V -> P
|
||||
Args:
|
||||
other:
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if isinstance(other, Point3):
|
||||
return Point3(other.x - self.x, other.y - self.y, other.z - self.z)
|
||||
else:
|
||||
raise TypeError(f"unsupported operand type(s) for -: '{type(other)}' and 'Vector3'")
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self * other: Vector3 => Vector3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __mul__(self, other: 'Vector3') -> 'Vector3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### `@overload`
|
||||
### *method* `self * other: RealNumber => Vector3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@overload
|
||||
def __mul__(self, other: RealNumber) -> 'Vector3':
|
||||
...
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self * other: int | float | Vector3 => Vector3`
|
||||
|
||||
|
||||
|
||||
**説明**: 数组运算 非点乘。点乘使用@,叉乘使用cross。
|
||||
|
||||
**變數説明**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __mul__(self, other: 'int | float | Vector3') -> 'Vector3':
|
||||
"""
|
||||
数组运算 非点乘。点乘使用@,叉乘使用cross。
|
||||
Args:
|
||||
other:
|
||||
|
||||
Returns:
|
||||
"""
|
||||
if isinstance(other, Vector3):
|
||||
return Vector3(self.x * other.x, self.y * other.y, self.z * other.z)
|
||||
elif isinstance(other, (float, int)):
|
||||
return Vector3(self.x * other, self.y * other, self.z * other)
|
||||
else:
|
||||
raise TypeError(f"unsupported operand type(s) for *: 'Vector3' and '{type(other)}'")
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self * other: RealNumber => Vector3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __rmul__(self, other: 'RealNumber') -> 'Vector3':
|
||||
return self.__mul__(other)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self @ other: Vector3 => RealNumber`
|
||||
|
||||
|
||||
|
||||
**説明**: 点乘。
|
||||
|
||||
**變數説明**:
|
||||
> - other:
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __matmul__(self, other: 'Vector3') -> 'RealNumber':
|
||||
"""
|
||||
点乘。
|
||||
Args:
|
||||
other:
|
||||
Returns:
|
||||
"""
|
||||
return self.x * other.x + self.y * other.y + self.z * other.z
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `self / other: RealNumber => Vector3`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __truediv__(self, other: RealNumber) -> 'Vector3':
|
||||
return Vector3(self.x / other, self.y / other, self.z / other)
|
||||
```
|
||||
</details>
|
||||
|
||||
### *method* `- self`
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
def __neg__(self):
|
||||
return Vector3(-self.x, -self.y, -self.z)
|
||||
```
|
||||
</details>
|
||||
|
||||
### ***var*** `zero_vector3 = Vector3(0, 0, 0)`
|
||||
|
||||
- **類型**: `Vector3`
|
||||
|
||||
- **説明**: 零向量
|
||||
|
||||
### ***var*** `x_axis = Vector3(1, 0, 0)`
|
||||
|
||||
- **類型**: `Vector3`
|
||||
|
||||
- **説明**: x轴单位向量
|
||||
|
||||
### ***var*** `y_axis = Vector3(0, 1, 0)`
|
||||
|
||||
- **類型**: `Vector3`
|
||||
|
||||
- **説明**: y轴单位向量
|
||||
|
||||
### ***var*** `z_axis = Vector3(0, 0, 1)`
|
||||
|
||||
- **類型**: `Vector3`
|
||||
|
||||
- **説明**: z轴单位向量
|
||||
|
@ -1,3 +0,0 @@
|
||||
---
|
||||
title: mbcp.particle
|
||||
---
|
@ -1,3 +0,0 @@
|
||||
---
|
||||
title: mbcp.presets
|
||||
---
|
@ -1,43 +0,0 @@
|
||||
---
|
||||
title: mbcp.presets.model
|
||||
---
|
||||
### **class** `GeometricModels`
|
||||
### `@staticmethod`
|
||||
### *method* `sphere(radius: float, density: float)`
|
||||
|
||||
|
||||
|
||||
**説明**: 生成球体上的点集。
|
||||
|
||||
**變數説明**:
|
||||
> - radius:
|
||||
> - density:
|
||||
|
||||
**返回**: List[Point3]: 球体上的点集。
|
||||
|
||||
|
||||
<details>
|
||||
<summary> <b>源碼</b> </summary>
|
||||
|
||||
```python
|
||||
@staticmethod
|
||||
def sphere(radius: float, density: float):
|
||||
"""
|
||||
生成球体上的点集。
|
||||
Args:
|
||||
radius:
|
||||
density:
|
||||
Returns:
|
||||
List[Point3]: 球体上的点集。
|
||||
"""
|
||||
area = 4 * np.pi * radius ** 2
|
||||
num = int(area * density)
|
||||
phi_list = np.arccos([clamp(-1 + (2.0 * _ - 1.0) / num, -1, 1) for _ in range(num)])
|
||||
theta_list = np.sqrt(num * np.pi) * phi_list
|
||||
x_array = radius * np.sin(phi_list) * np.cos(theta_list)
|
||||
y_array = radius * np.sin(phi_list) * np.sin(theta_list)
|
||||
z_array = radius * np.cos(phi_list)
|
||||
return [Point3(x_array[i], y_array[i], z_array[i]) for i in range(num)]
|
||||
```
|
||||
</details>
|
||||
|
Loading…
Reference in New Issue
Block a user