📝 测试文档部署

This commit is contained in:
2024-08-28 12:02:30 +08:00
parent f5d91cafd5
commit e0a3ab605d
39 changed files with 2811 additions and 819 deletions

View File

@ -1,6 +1,3 @@
---
title: mbcp.\n\ninit\n\n
order: 1
icon: laptop-code
category: API
---
title: mbcp
---

View File

@ -1,26 +1,25 @@
---
title: mbcp.mp\nmath.angle
order: 1
icon: laptop-code
category: API
title: mbcp.mp_math.angle
---
### ***class*** `Angle`
### ***class*** `AnyAngle`
- #### *def* `__init__(self, value: float, is_radian: bool = False)`
###   ***def*** `__init__(self, value: float, is_radian: bool) -> None`
任意角度。
 任意角度。
参数:
Args:
value: 角度或弧度值
value: 角度或弧度值
is_radian: 是否为弧度,默认为否
is_radian: 是否为弧度,默认为否
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def __init__(self, value: float, is_radian: bool=False):
@ -37,17 +36,20 @@ def __init__(self, value: float, is_radian: bool=False):
```
</details>
### &emsp; ***@property***
### &emsp; ***def*** `complementary(self: Any) -> 'AnyAngle'`
- #### `@property`
- #### *def* `complementary(self)`
&emsp;余角两角的和为90°。
Returns:
余角两角的和为90°。
余角
返回:
余角
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
@property
@ -61,17 +63,20 @@ def complementary(self) -> 'AnyAngle':
```
</details>
### &emsp; ***@property***
### &emsp; ***def*** `supplementary(self: Any) -> 'AnyAngle'`
- #### `@property`
- #### *def* `supplementary(self)`
&emsp;补角两角的和为180°。
Returns:
补角两角的和为180°。
补角
返回:
补角
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
@property
@ -85,17 +90,20 @@ def supplementary(self) -> 'AnyAngle':
```
</details>
### &emsp; ***@property***
### &emsp; ***def*** `degree(self: Any) -> float`
- #### `@property`
- #### *def* `degree(self)`
&emsp;角度。
Returns:
角度。
弧度
返回:
弧度
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
@property
@ -109,17 +117,20 @@ def degree(self) -> float:
```
</details>
### &emsp; ***@property***
### &emsp; ***def*** `minimum_positive(self: Any) -> 'AnyAngle'`
- #### `@property`
- #### *def* `minimum_positive(self)`
&emsp;最小正角。
Returns:
最小正角。
最小正角度
返回:
最小正角度
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
@property
@ -133,17 +144,20 @@ def minimum_positive(self) -> 'AnyAngle':
```
</details>
### &emsp; ***@property***
### &emsp; ***def*** `maximum_negative(self: Any) -> 'AnyAngle'`
- #### `@property`
- #### *def* `maximum_negative(self)`
&emsp;最大负角。
Returns:
最大负角。
最大负角度
返回:
最大负角度
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
@property
@ -157,17 +171,20 @@ def maximum_negative(self) -> 'AnyAngle':
```
</details>
### &emsp; ***@property***
### &emsp; ***def*** `sin(self: Any) -> float`
- #### `@property`
- #### *def* `sin(self)`
&emsp;正弦值。
Returns:
正弦值。
正弦值
返回:
正弦值
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
@property
@ -181,17 +198,20 @@ def sin(self) -> float:
```
</details>
### &emsp; ***@property***
### &emsp; ***def*** `cos(self: Any) -> float`
- #### `@property`
- #### *def* `cos(self)`
&emsp;余弦值。
Returns:
余弦值。
余弦值
返回:
余弦值
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
@property
@ -205,17 +225,20 @@ def cos(self) -> float:
```
</details>
### &emsp; ***@property***
### &emsp; ***def*** `tan(self: Any) -> float`
- #### `@property`
- #### *def* `tan(self)`
&emsp;正切值。
Returns:
正切值。
正切值
返回:
正切值
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
@property
@ -229,17 +252,20 @@ def tan(self) -> float:
```
</details>
### &emsp; ***@property***
### &emsp; ***def*** `cot(self: Any) -> float`
- #### `@property`
- #### *def* `cot(self)`
&emsp;余切值。
Returns:
余切值。
余切值
返回:
余切值
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
@property
@ -253,17 +279,20 @@ def cot(self) -> float:
```
</details>
### &emsp; ***@property***
### &emsp; ***def*** `sec(self: Any) -> float`
- #### `@property`
- #### *def* `sec(self)`
&emsp;正割值。
Returns:
正割值。
正割值
返回:
正割值
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
@property
@ -277,17 +306,20 @@ def sec(self) -> float:
```
</details>
### &emsp; ***@property***
### &emsp; ***def*** `csc(self: Any) -> float`
- #### `@property`
- #### *def* `csc(self)`
&emsp;余割值。
Returns:
余割值。
余割值
返回:
余割值
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
@property
@ -301,3 +333,117 @@ def csc(self) -> float:
```
</details>
- #### *def* `__add__(self, other: 'AnyAngle')`
- #
<details>
<summary>源码</summary>
```python
def __add__(self, other: 'AnyAngle') -> 'AnyAngle':
return AnyAngle(self.radian + other.radian, is_radian=True)
```
</details>
- #### *def* `__eq__(self, other)`
- #
<details>
<summary>源码</summary>
```python
def __eq__(self, other):
return approx(self.radian, other.radian)
```
</details>
- #### *def* `__sub__(self, other: 'AnyAngle')`
- #
<details>
<summary>源码</summary>
```python
def __sub__(self, other: 'AnyAngle') -> 'AnyAngle':
return AnyAngle(self.radian - other.radian, is_radian=True)
```
</details>
- #### *def* `__mul__(self, other: float)`
- #
<details>
<summary>源码</summary>
```python
def __mul__(self, other: float) -> 'AnyAngle':
return AnyAngle(self.radian * other, is_radian=True)
```
</details>
- #### *def* `__repr__(self)`
- #
<details>
<summary>源码</summary>
```python
def __repr__(self):
return f'AnyAngle({self.radian}, is_radian=True)'
```
</details>
- #### *def* `__str__(self)`
- #
<details>
<summary>源码</summary>
```python
def __str__(self):
return f'AnyAngle({self.degree}° or {self.radian} rad)'
```
</details>
- #### `@overload`
- #### *def* `__truediv__(self, other: float)`
- #
<details>
<summary>源码</summary>
```python
@overload
def __truediv__(self, other: float) -> 'AnyAngle':
...
```
</details>
- #### `@overload`
- #### *def* `__truediv__(self, other: 'AnyAngle')`
- #
<details>
<summary>源码</summary>
```python
@overload
def __truediv__(self, other: 'AnyAngle') -> float:
...
```
</details>
- #### *def* `__truediv__(self, other)`
- #
<details>
<summary>源码</summary>
```python
def __truediv__(self, other):
if isinstance(other, AnyAngle):
return self.radian / other.radian
return AnyAngle(self.radian / other, is_radian=True)
```
</details>

View File

@ -1,31 +1,15 @@
---
title: mbcp.mp\nmath.const
order: 1
icon: laptop-code
category: API
title: mbcp.mp_math.const
---
### ***var*** `PI = math.pi`
### ***var*** `E = math.e`
### ***var*** `GOLDEN_RATIO = (1 + math.sqrt(5)) / 2`
### ***var*** `GAMMA = 0.5772156649015329`
### ***var*** `EPSILON = 0.0001`
### ***var*** `APPROX = 0.001`

View File

@ -1,32 +1,25 @@
---
title: mbcp.mp\nmath.equation
order: 1
icon: laptop-code
category: API
title: mbcp.mp_math.equation
---
### ***var*** `result_func = get_partial_derivative_func(result_func, v, epsilon)`
### *def* `get_partial_derivative_func(func: MultiVarsFunc = EPSILON)`
### ***def*** `get_partial_derivative_func(func: MultiVarsFunc, var: int | tuple[int, ...], epsilon: Number) -> MultiVarsFunc`
求N元函数一阶偏导函数。这玩意不太稳定慎用。
Args:
参数:
func: 函数
func: 函数
var: 变量位置,可为整数(一阶偏导)或整数元组(高阶偏导)
var: 变量位置,可为整数(一阶偏导)或整数元组(高阶偏导)
epsilon: 偏移量
epsilon: 偏移量
Returns:
偏导函数
Raises:
ValueError: 无效变量类型
<details>
<summary></summary>
<summary>源码</summary>
```python
def get_partial_derivative_func(func: MultiVarsFunc, var: int | tuple[int, ...], epsilon: Number=EPSILON) -> MultiVarsFunc:
@ -63,12 +56,11 @@ def get_partial_derivative_func(func: MultiVarsFunc, var: int | tuple[int, ...],
```
</details>
### ***def*** `partial_derivative_func() -> Var`
### *def* `partial_derivative_func()`
<details>
<summary></summary>
<summary>源码</summary>
```python
def partial_derivative_func(*args: Var) -> Var:
@ -80,12 +72,11 @@ def partial_derivative_func(*args: Var) -> Var:
```
</details>
### ***def*** `high_order_partial_derivative_func() -> Var`
### *def* `high_order_partial_derivative_func()`
<details>
<summary></summary>
<summary>源码</summary>
```python
def high_order_partial_derivative_func(*args: Var) -> Var:
@ -98,28 +89,32 @@ def high_order_partial_derivative_func(*args: Var) -> Var:
### ***class*** `CurveEquation`
- #### *def* `__init__(self, x_func: OneVarFunc, y_func: OneVarFunc, z_func: OneVarFunc)`
### &emsp; ***def*** `__init__(self, x_func: OneVarFunc, y_func: OneVarFunc, z_func: OneVarFunc) -> None`
曲线方程。
&emsp;曲线方程。
参数:
:param x_func:
x_func: x函数
:param y_func:
y_func: y函数
:param z_func:
z_func: z函数
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def __init__(self, x_func: OneVarFunc, y_func: OneVarFunc, z_func: OneVarFunc):
"""
曲线方程。
:param x_func:
:param y_func:
:param z_func:
Args:
x_func: x函数
y_func: y函数
z_func: z函数
"""
self.x_func = x_func
self.y_func = y_func
@ -127,19 +122,48 @@ def __init__(self, x_func: OneVarFunc, y_func: OneVarFunc, z_func: OneVarFunc):
```
</details>
### ***var*** `args_list_plus = list(args)`
- #### *def* `__call__(self)`
计算曲线上的点。
### ***var*** `args_list_minus = list(args)`
参数:
*t:
参数:
- #
<details>
<summary>源码</summary>
### ***var*** `result_func = func`
```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>
- #### *def* `__str__(self)`
### ***var*** `result_func = get_partial_derivative_func(result_func, v, epsilon)`
- #
<details>
<summary>源码</summary>
```python
def __str__(self):
return 'CurveEquation()'
```
</details>

View File

@ -1,7 +1,3 @@
---
title: mbcp.mp\nmath.\n\ninit\n\n
order: 1
icon: laptop-code
category: API
title: mbcp.mp_math
---

View File

@ -1,26 +1,23 @@
---
title: mbcp.mp\nmath.line
order: 1
icon: laptop-code
category: API
title: mbcp.mp_math.line
---
### ***class*** `Line3`
- #### *def* `__init__(self, point: 'Point3', direction: 'Vector3')`
### &emsp; ***def*** `__init__(self, point: 'Point3', direction: 'Vector3') -> None`
三维空间中的直线。由一个点和一个方向向量确定。
&emsp;三维空间中的直线。由一个点和一个方向向量确定。
参数:
Args:
point: 直线上的一点
point: 直线上的一点
direction: 直线的方向向量
direction: 直线的方向向量
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def __init__(self, point: 'Point3', direction: 'Vector3'):
@ -35,22 +32,21 @@ def __init__(self, point: 'Point3', direction: 'Vector3'):
```
</details>
### &emsp; ***def*** `approx(self, other: 'Line3', epsilon: float) -> bool`
- #### *def* `approx(self, other: 'Line3', epsilon: float = APPROX)`
&emsp;判断两条直线是否近似相等。
Args:
判断两条直线是否近似相等。
other: 另一条直线
参数:
epsilon: 误差
other: 另一条直线
Returns:
epsilon: 误差
是否近似相等
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def approx(self, other: 'Line3', epsilon: float=APPROX) -> bool:
@ -66,24 +62,19 @@ def approx(self, other: 'Line3', epsilon: float=APPROX) -> bool:
```
</details>
### &emsp; ***def*** `cal_angle(self, other: 'Line3') -> 'AnyAngle'`
- #### *def* `cal_angle(self, other: 'Line3')`
&emsp;计算直线和直线之间的夹角。
Args:
计算直线和直线之间的夹角。
other: 另一条直线
参数:
Returns:
other: 另一条直线
夹角弧度
Raises:
TypeError: 不支持的类型
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def cal_angle(self, other: 'Line3') -> 'AnyAngle':
@ -100,26 +91,19 @@ def cal_angle(self, other: 'Line3') -> 'AnyAngle':
```
</details>
### &emsp; ***def*** `cal_distance(self, other: 'Line3 | Point3') -> float`
&emsp;计算直线和直线或点之间的距离。
Args:
other: 平行直线或点
- #### *def* `cal_distance(self, other: 'Line3 | Point3')`
计算直线和直线或点之间的距离。
Returns:
参数:
距离
other: 平行直线或点
Raises:
TypeError: 不支持的类型
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def cal_distance(self, other: 'Line3 | Point3') -> float:
@ -149,26 +133,19 @@ def cal_distance(self, other: 'Line3 | Point3') -> float:
```
</details>
### &emsp; ***def*** `cal_intersection(self, other: 'Line3') -> 'Point3'`
- #### *def* `cal_intersection(self, other: 'Line3')`
&emsp;计算两条直线的交点。
Args:
计算两条直线的交点。
other: 另一条直线
参数:
Returns:
other: 另一条直线
交点
Raises:
ValueError: 直线平行
ValueError: 直线不共面
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def cal_intersection(self, other: 'Line3') -> 'Point3':
@ -190,20 +167,19 @@ def cal_intersection(self, other: 'Line3') -> 'Point3':
```
</details>
### &emsp; ***def*** `cal_perpendicular(self, point: 'Point3') -> 'Line3'`
- #### *def* `cal_perpendicular(self, point: 'Point3')`
&emsp;计算直线经过指定点p的垂线。
Args:
计算直线经过指定点p的垂线。
point: 指定点
参数:
Returns:
point: 指定点
垂线
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def cal_perpendicular(self, point: 'Point3') -> 'Line3':
@ -218,20 +194,19 @@ def cal_perpendicular(self, point: 'Point3') -> 'Line3':
```
</details>
### &emsp; ***def*** `get_point(self, t: RealNumber) -> 'Point3'`
- #### *def* `get_point(self, t: RealNumber)`
&emsp;获取直线上的点。同一条直线但起始点和方向向量不同则同一个t对应的点不同。
Args:
获取直线上的点。同一条直线但起始点和方向向量不同则同一个t对应的点不同。
t: 参数t
参数:
Returns:
t: 参数t
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def get_point(self, t: RealNumber) -> 'Point3':
@ -246,16 +221,19 @@ def get_point(self, t: RealNumber) -> 'Point3':
```
</details>
### &emsp; ***def*** `get_parametric_equations(self) -> tuple[OneSingleVarFunc, OneSingleVarFunc, OneSingleVarFunc]`
- #### *def* `get_parametric_equations(self)`
&emsp;获取直线的参数方程。
Returns:
获取直线的参数方程。
x(t), y(t), z(t)
返回:
x(t), y(t), z(t)
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def get_parametric_equations(self) -> tuple[OneSingleVarFunc, OneSingleVarFunc, OneSingleVarFunc]:
@ -268,22 +246,21 @@ def get_parametric_equations(self) -> tuple[OneSingleVarFunc, OneSingleVarFunc,
```
</details>
### &emsp; ***def*** `is_approx_parallel(self, other: 'Line3', epsilon: float) -> bool`
- #### *def* `is_approx_parallel(self, other: 'Line3', epsilon: float = 1e-06)`
&emsp;判断两条直线是否近似平行。
Args:
判断两条直线是否近似平行。
other: 另一条直线
参数:
epsilon: 误差
other: 另一条直线
Returns:
epsilon: 误差
是否近似平行
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def is_approx_parallel(self, other: 'Line3', epsilon: float=1e-06) -> bool:
@ -299,20 +276,19 @@ def is_approx_parallel(self, other: 'Line3', epsilon: float=1e-06) -> bool:
```
</details>
### &emsp; ***def*** `is_parallel(self, other: 'Line3') -> bool`
- #### *def* `is_parallel(self, other: 'Line3')`
&emsp;判断两条直线是否平行。
Args:
判断两条直线是否平行。
other: 另一条直线
参数:
Returns:
other: 另一条直线
是否平行
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def is_parallel(self, other: 'Line3') -> bool:
@ -327,20 +303,19 @@ def is_parallel(self, other: 'Line3') -> bool:
```
</details>
### &emsp; ***def*** `is_collinear(self, other: 'Line3') -> bool`
- #### *def* `is_collinear(self, other: 'Line3')`
&emsp;判断两条直线是否共线。
Args:
判断两条直线是否共线。
other: 另一条直线
参数:
Returns:
other: 另一条直线
是否共线
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def is_collinear(self, other: 'Line3') -> bool:
@ -355,20 +330,19 @@ def is_collinear(self, other: 'Line3') -> bool:
```
</details>
### &emsp; ***def*** `is_point_on(self, point: 'Point3') -> bool`
- #### *def* `is_point_on(self, point: 'Point3')`
&emsp;判断点是否在直线上。
Args:
判断点是否在直线上。
point: 点
参数:
Returns:
point: 点
是否在直线上
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def is_point_on(self, point: 'Point3') -> bool:
@ -383,22 +357,20 @@ def is_point_on(self, point: 'Point3') -> bool:
```
</details>
### &emsp; ***def*** `is_coplanar(self, other: 'Line3') -> bool`
- #### *def* `is_coplanar(self, other: 'Line3')`
&emsp;判断两条直线是否共面。
判断两条直线是否共面。
充要条件两直线方向向量的叉乘与两直线上任意一点的向量的点积为0。
Args:
参数:
other: 另一条直线
other: 另一条直线
Returns:
是否共面
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def is_coplanar(self, other: 'Line3') -> bool:
@ -414,18 +386,18 @@ def is_coplanar(self, other: 'Line3') -> bool:
```
</details>
### &emsp; ***def*** `simplify(self) -> None`
- #### *def* `simplify(self)`
&emsp;简化直线方程,等价相等。
简化直线方程,等价相等。
自体简化,不返回值。
按照可行性一次对x y z 化 0 处理,并对向量单位化
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def simplify(self):
@ -445,23 +417,22 @@ def simplify(self):
```
</details>
### &emsp; ***@classmethod***
### &emsp; ***def*** `from_two_points(cls: Any, p1: 'Point3', p2: 'Point3') -> 'Line3'`
- #### `@classmethod`
- #### *def* `from_two_points(cls, p1: 'Point3', p2: 'Point3')`
&emsp;工厂函数 由两点构造直线。
Args:
工厂函数 由两点构造直线。
p1: 点1
参数:
p2: 点2
p1: 点1
Returns:
p2: 点2
直线
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
@classmethod
@ -479,11 +450,107 @@ def from_two_points(cls, p1: 'Point3', p2: 'Point3') -> 'Line3':
```
</details>
### ***var*** `direction = p2 - p1`
- #### *def* `__and__(self, other: 'Line3')`
计算两条直线点集合的交集。重合线返回自身平行线返回None交线返回交点。
参数:
other: 另一条直线
- #
<details>
<summary>源码</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>
- #### *def* `__eq__(self, other)`
判断两条直线是否等价。
v1 // v2 ∧ (p1 - p2) // v1
参数:
other:
- #
<details>
<summary>源码</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>
- #### *def* `__str__(self)`
### ***var*** `s = 'Line3: '`
- #
<details>
<summary>源码</summary>
```python
def __str__(self):
"""
返回点向式x-x0
Returns:
"""
s = 'Line3: '
if self.direction.x != 0:
s += f'(x{sign_format(-self.point.x)})/{self.direction.x}'
if self.direction.y != 0:
s += f' = (y{sign_format(-self.point.y)})/{self.direction.y}'
if self.direction.z != 0:
s += f' = (z{sign_format(-self.point.z)})/{self.direction.z}'
return s
```
</details>
- #### *def* `__repr__(self)`
- #
<details>
<summary>源码</summary>
```python
def __repr__(self):
return f'Line3({self.point}, {self.direction})'
```
</details>

View File

@ -1,15 +1,37 @@
---
title: mbcp.mp\nmath.mp\nmath\ntyping
order: 1
icon: laptop-code
category: API
title: mbcp.mp_math.mp_math_typing
---
### ***var*** `RealNumber: TypeAlias = int | float`
### ***var*** `Number: TypeAlias = RealNumber | complex`
### ***var*** `SingleVar = TypeVar('SingleVar', bound=Number)`
### ***var*** `ArrayVar = TypeVar('ArrayVar', bound=Iterable[Number])`
### ***var*** `Var: TypeAlias = SingleVar | ArrayVar`
### ***var*** `OneSingleVarFunc: TypeAlias = Callable[[SingleVar], SingleVar]`
### ***var*** `OneArrayFunc: TypeAlias = Callable[[ArrayVar], ArrayVar]`
### ***var*** `OneVarFunc: TypeAlias = OneSingleVarFunc | OneArrayFunc`
### ***var*** `TwoSingleVarsFunc: TypeAlias = Callable[[SingleVar, SingleVar], SingleVar]`
### ***var*** `TwoArraysFunc: TypeAlias = Callable[[ArrayVar, ArrayVar], ArrayVar]`
### ***var*** `TwoVarsFunc: TypeAlias = TwoSingleVarsFunc | TwoArraysFunc`
### ***var*** `ThreeSingleVarsFunc: TypeAlias = Callable[[SingleVar, SingleVar, SingleVar], SingleVar]`
### ***var*** `ThreeArraysFunc: TypeAlias = Callable[[ArrayVar, ArrayVar, ArrayVar], ArrayVar]`
### ***var*** `ThreeVarsFunc: TypeAlias = ThreeSingleVarsFunc | ThreeArraysFunc`
### ***var*** `MultiSingleVarsFunc: TypeAlias = Callable[..., SingleVar]`
### ***var*** `MultiArraysFunc: TypeAlias = Callable[..., ArrayVar]`
### ***var*** `MultiVarsFunc: TypeAlias = MultiSingleVarsFunc | MultiArraysFunc`

View File

@ -1,30 +1,47 @@
---
title: mbcp.mp\nmath.plane
order: 1
icon: laptop-code
category: API
title: mbcp.mp_math.plane
---
### ***var*** `k = other.a / self.a`
### ***var*** `A = np.array([[self.b, self.c], [other.b, other.c]])`
### ***var*** `B = np.array([-self.d, -other.d])`
### ***var*** `v2 = l2.get_point(1) - l1.point`
### ***var*** `k = other.b / self.b`
### ***var*** `A = np.array([[self.a, self.c], [other.a, other.c]])`
### ***var*** `B = np.array([-self.d, -other.d])`
### ***var*** `k = other.c / self.c`
### ***var*** `A = np.array([[self.a, self.b], [other.a, other.b]])`
### ***var*** `B = np.array([-self.d, -other.d])`
### ***class*** `Plane3`
- #### *def* `__init__(self, a: float, b: float, c: float, d: float)`
### &emsp; ***def*** `__init__(self, a: float, b: float, c: float, d: float) -> None`
平面方程ax + by + cz + d = 0
&emsp;平面方程ax + by + cz + d = 0
参数:
Args:
a:
a:
b:
b:
c:
c:
d:
d:
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def __init__(self, a: float, b: float, c: float, d: float):
@ -43,32 +60,26 @@ def __init__(self, a: float, b: float, c: float, d: float):
```
</details>
### &emsp; ***def*** `approx(self, other: 'Plane3', epsilon: float) -> bool`
&emsp;判断两个平面是否近似相等。
Args:
other:
epsilon:
- #### *def* `approx(self, other: 'Plane3')`
判断两个平面是否近似相等。
Returns:
参数:
是否近似相等
other:
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def approx(self, other: 'Plane3', epsilon: float=APPROX) -> bool:
def approx(self, other: 'Plane3') -> bool:
"""
判断两个平面是否近似相等。
Args:
other:
epsilon:
Returns:
是否近似相等
@ -87,24 +98,19 @@ def approx(self, other: 'Plane3', epsilon: float=APPROX) -> bool:
```
</details>
### &emsp; ***def*** `cal_angle(self, other: 'Line3 | Plane3') -> 'AnyAngle'`
- #### *def* `cal_angle(self, other: 'Line3 | Plane3')`
&emsp;计算平面与平面之间的夹角。
Args:
计算平面与平面之间的夹角。
other: 另一个平面
参数:
Returns:
other: 另一个平面
夹角弧度
Raises:
TypeError: 不支持的类型
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def cal_angle(self, other: 'Line3 | Plane3') -> 'AnyAngle':
@ -126,24 +132,19 @@ def cal_angle(self, other: 'Line3 | Plane3') -> 'AnyAngle':
```
</details>
### &emsp; ***def*** `cal_distance(self, other: 'Plane3 | Point3') -> float`
- #### *def* `cal_distance(self, other: 'Plane3 | Point3')`
&emsp;计算平面与平面或点之间的距离。
Args:
计算平面与平面或点之间的距离。
other: 另一个平面或点
参数:
Returns:
other: 另一个平面或点
距离
Raises:
TypeError: 不支持的类型
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def cal_distance(self, other: 'Plane3 | Point3') -> float:
@ -165,22 +166,19 @@ def cal_distance(self, other: 'Plane3 | Point3') -> float:
```
</details>
### &emsp; ***def*** `cal_intersection_line3(self, other: 'Plane3') -> 'Line3'`
- #### *def* `cal_intersection_line3(self, other: 'Plane3')`
&emsp;计算两平面的交线。该方法有问题,待修复。
Args:
计算两平面的交线。该方法有问题,待修复。
other: 另一个平面
参数:
Returns:
other: 另一个平面
交线
Raises:
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def cal_intersection_line3(self, other: 'Plane3') -> 'Line3':
@ -212,24 +210,19 @@ def cal_intersection_line3(self, other: 'Plane3') -> 'Line3':
```
</details>
### &emsp; ***def*** `cal_intersection_point3(self, other: 'Line3') -> 'Point3'`
- #### *def* `cal_intersection_point3(self, other: 'Line3')`
&emsp;计算平面与直线的交点。
Args:
计算平面与直线的交点。
other: 不与平面平行或在平面上的直线
参数:
Returns:
other: 不与平面平行或在平面上的直线
交点
Raises:
ValueError: 平面与直线平行或重合
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def cal_intersection_point3(self, other: 'Line3') -> 'Point3':
@ -250,20 +243,19 @@ def cal_intersection_point3(self, other: 'Line3') -> 'Point3':
```
</details>
### &emsp; ***def*** `cal_parallel_plane3(self, point: 'Point3') -> 'Plane3'`
- #### *def* `cal_parallel_plane3(self, point: 'Point3')`
&emsp;计算平行于该平面且过指定点的平面。
Args:
计算平行于该平面且过指定点的平面。
point: 指定点
参数:
Returns:
point: 指定点
平面
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def cal_parallel_plane3(self, point: 'Point3') -> 'Plane3':
@ -278,20 +270,19 @@ def cal_parallel_plane3(self, point: 'Point3') -> 'Plane3':
```
</details>
### &emsp; ***def*** `is_parallel(self, other: 'Plane3') -> bool`
- #### *def* `is_parallel(self, other: 'Plane3')`
&emsp;判断两个平面是否平行。
Args:
判断两个平面是否平行。
other: 另一个平面
参数:
Returns:
other: 另一个平面
是否平行
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def is_parallel(self, other: 'Plane3') -> bool:
@ -306,17 +297,20 @@ def is_parallel(self, other: 'Plane3') -> bool:
```
</details>
### &emsp; ***@property***
### &emsp; ***def*** `normal(self: Any) -> 'Vector3'`
- #### `@property`
- #### *def* `normal(self)`
&emsp;平面的法向量。
Returns:
平面的法向量。
法向量
返回:
法向量
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
@property
@ -330,23 +324,22 @@ def normal(self) -> 'Vector3':
```
</details>
### &emsp; ***@classmethod***
### &emsp; ***def*** `from_point_and_normal(cls: Any, point: 'Point3', normal: 'Vector3') -> 'Plane3'`
- #### `@classmethod`
- #### *def* `from_point_and_normal(cls, point: 'Point3', normal: 'Vector3')`
&emsp;工厂函数 由点和法向量构造平面(点法式构造)。
Args:
工厂函数 由点和法向量构造平面(点法式构造)。
point: 平面上的一点
参数:
normal: 法向量
point: 平面上的一点
Returns:
normal: 法向量
平面
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
@classmethod
@ -365,25 +358,24 @@ def from_point_and_normal(cls, point: 'Point3', normal: 'Vector3') -> 'Plane3':
```
</details>
### &emsp; ***@classmethod***
### &emsp; ***def*** `from_three_points(cls: Any, p1: 'Point3', p2: 'Point3', p3: 'Point3') -> 'Plane3'`
- #### `@classmethod`
- #### *def* `from_three_points(cls, p1: 'Point3', p2: 'Point3', p3: 'Point3')`
&emsp;工厂函数 由三点构造平面。
Args:
工厂函数 由三点构造平面。
p1: 点1
参数:
p2: 点2
p1: 点1
p3: 点3
p2: 点2
Returns:
p3: 点3
平面
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
@classmethod
@ -404,23 +396,22 @@ def from_three_points(cls, p1: 'Point3', p2: 'Point3', p3: 'Point3') -> 'Plane3'
```
</details>
### &emsp; ***@classmethod***
### &emsp; ***def*** `from_two_lines(cls: Any, l1: 'Line3', l2: 'Line3') -> 'Plane3'`
- #### `@classmethod`
- #### *def* `from_two_lines(cls, l1: 'Line3', l2: 'Line3')`
&emsp;工厂函数 由两直线构造平面。
Args:
工厂函数 由两直线构造平面。
l1: 直线1
参数:
l2: 直线2
l1: 直线1
Returns:
l2: 直线2
平面
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
@classmethod
@ -441,23 +432,22 @@ def from_two_lines(cls, l1: 'Line3', l2: 'Line3') -> 'Plane3':
```
</details>
### &emsp; ***@classmethod***
### &emsp; ***def*** `from_point_and_line(cls: Any, point: 'Point3', line: 'Line3') -> 'Plane3'`
- #### `@classmethod`
- #### *def* `from_point_and_line(cls, point: 'Point3', line: 'Line3')`
&emsp;工厂函数 由点和直线构造平面。
Args:
工厂函数 由点和直线构造平面。
point: 面上一点
参数:
line: 面上直线,不包含点
point: 面上一点
Returns:
line: 面上直线,不包含点
平面
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
@classmethod
@ -474,79 +464,124 @@ def from_point_and_line(cls, point: 'Point3', line: 'Line3') -> 'Plane3':
```
</details>
### ***var*** `direction = self.normal.cross(other.normal)`
- #### *def* `__repr__(self)`
- #
<details>
<summary>源码</summary>
```python
def __repr__(self):
return f'Plane3({self.a}, {self.b}, {self.c}, {self.d})'
```
</details>
- #### *def* `__str__(self)`
- #
<details>
<summary>源码</summary>
```python
def __str__(self):
s = 'Plane3: '
if self.a != 0:
s += f'{sign(self.a, only_neg=True)}{abs(self.a)}x'
if self.b != 0:
s += f' {sign(self.b)} {abs(self.b)}y'
if self.c != 0:
s += f' {sign(self.c)} {abs(self.c)}z'
if self.d != 0:
s += f' {sign(self.d)} {abs(self.d)}'
return s + ' = 0'
```
</details>
- #### `@overload`
- #### *def* `__and__(self, other: 'Line3')`
- #
<details>
<summary>源码</summary>
```python
@overload
def __and__(self, other: 'Line3') -> 'Point3 | None':
...
```
</details>
- #### `@overload`
- #### *def* `__and__(self, other: 'Plane3')`
- #
<details>
<summary>源码</summary>
```python
@overload
def __and__(self, other: 'Plane3') -> 'Line3 | None':
...
```
</details>
- #### *def* `__and__(self, other)`
取两平面的交集(人话:交线)
### ***var*** `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)`
参数:
other:
- #
<details>
<summary>源码</summary>
### ***var*** `d = -a * point.x - b * point.y - c * point.z`
```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>
- #### *def* `__eq__(self, other)`
- #
<details>
<summary>源码</summary>
### ***var*** `v1 = p2 - p1`
```python
def __eq__(self, other) -> bool:
return self.approx(other)
```
</details>
- #### *def* `__rand__(self, other: 'Line3')`
- #
<details>
<summary>源码</summary>
### ***var*** `v2 = p3 - p1`
### ***var*** `normal = v1.cross(v2)`
### ***var*** `v1 = l1.direction`
### ***var*** `v2 = l2.point - l1.point`
### ***var*** `s = 'Plane3: '`
### ***var*** `k = other.a / self.a`
### ***var*** `A = np.array([[self.b, self.c], [other.b, other.c]])`
### ***var*** `B = np.array([-self.d, -other.d])`
### ***var*** `v2 = l2.get_point(1) - l1.point`
### ***var*** `k = other.b / self.b`
### ***var*** `A = np.array([[self.a, self.c], [other.a, other.c]])`
### ***var*** `B = np.array([-self.d, -other.d])`
### ***var*** `k = other.c / self.c`
### ***var*** `A = np.array([[self.a, self.b], [other.a, other.b]])`
### ***var*** `B = np.array([-self.d, -other.d])`
```python
def __rand__(self, other: 'Line3') -> 'Point3':
return self.cal_intersection_point3(other)
```
</details>

View File

@ -1,28 +1,25 @@
---
title: mbcp.mp\nmath.point
order: 1
icon: laptop-code
category: API
title: mbcp.mp_math.point
---
### ***class*** `Point3`
- #### *def* `__init__(self, x: float, y: float, z: float)`
### &emsp; ***def*** `__init__(self, x: float, y: float, z: float) -> None`
笛卡尔坐标系中的点。
&emsp;笛卡尔坐标系中的点。
参数:
Args:
x: x 坐标
x: x 坐标
y: y 坐标
y: y 坐标
z: z 坐标
z: z 坐标
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def __init__(self, x: float, y: float, z: float):
@ -39,24 +36,21 @@ def __init__(self, x: float, y: float, z: float):
```
</details>
### &emsp; ***def*** `approx(self, other: 'Point3', epsilon: float) -> bool`
&emsp;判断两个点是否近似相等。
Args:
other:
epsilon:
- #### *def* `approx(self, other: 'Point3', epsilon: float = APPROX)`
判断两个点是否近似相等。
Returns:
参数:
是否近似相等
other:
epsilon:
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def approx(self, other: 'Point3', epsilon: float=APPROX) -> bool:
@ -73,3 +67,97 @@ def approx(self, other: 'Point3', epsilon: float=APPROX) -> bool:
```
</details>
- #### *def* `__str__(self)`
- #
<details>
<summary>源码</summary>
```python
def __str__(self):
return f'Point3({self.x}, {self.y}, {self.z})'
```
</details>
- #### `@overload`
- #### *def* `__add__(self, other: 'Vector3')`
- #
<details>
<summary>源码</summary>
```python
@overload
def __add__(self, other: 'Vector3') -> 'Point3':
...
```
</details>
- #### `@overload`
- #### *def* `__add__(self, other: 'Point3')`
- #
<details>
<summary>源码</summary>
```python
@overload
def __add__(self, other: 'Point3') -> 'Point3':
...
```
</details>
- #### *def* `__add__(self, other)`
P + V -> P
P + P -> P
参数:
other:
- #
<details>
<summary>源码</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>
- #### *def* `__eq__(self, other)`
判断两个点是否相等。
参数:
other:
- #
<details>
<summary>源码</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>

View File

@ -1,24 +1,19 @@
---
title: mbcp.mp\nmath.segment
order: 1
icon: laptop-code
category: API
title: mbcp.mp_math.segment
---
### ***class*** `Segment3`
- #### *def* `__init__(self, p1: 'Point3', p2: 'Point3')`
### &emsp; ***def*** `__init__(self, p1: 'Point3', p2: 'Point3') -> None`
&emsp;三维空间中的线段。
三维空间中的线段。
:param p1:
:param p2:
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def __init__(self, p1: 'Point3', p2: 'Point3'):
@ -38,3 +33,27 @@ def __init__(self, p1: 'Point3', p2: 'Point3'):
```
</details>
- #### *def* `__repr__(self)`
- #
<details>
<summary>源码</summary>
```python
def __repr__(self):
return f'Segment3({self.p1}, {self.p2})'
```
</details>
- #### *def* `__str__(self)`
- #
<details>
<summary>源码</summary>
```python
def __str__(self):
return f'Segment3({self.p1} -> {self.p2})'
```
</details>

View File

@ -1,30 +1,23 @@
---
title: mbcp.mp\nmath.utils
order: 1
icon: laptop-code
category: API
title: mbcp.mp_math.utils
---
### *def* `clamp()`
### ***def*** `clamp(x: float, min_: float, max_: float) -> float`
区间截断函数。
Args:
参数:
x:
x:
min_:
min_:
max_:
max_:
Returns:
限制后的值
<details>
<summary></summary>
<summary>源码</summary>
```python
def clamp(x: float, min_: float, max_: float) -> float:
@ -42,26 +35,23 @@ def clamp(x: float, min_: float, max_: float) -> float:
```
</details>
### ***def*** `approx(x: float, y: float, epsilon: float) -> bool`
### *def* `approx(x: float = 0.0, y: float = APPROX)`
判断两个数是否近似相等。或包装一个实数用于判断是否近似于0。
Args:
参数:
x:
x:
y:
y:
epsilon:
epsilon:
Returns:
是否近似相等
<details>
<summary></summary>
<summary>源码</summary>
```python
def approx(x: float, y: float=0.0, epsilon: float=APPROX) -> bool:
@ -79,22 +69,21 @@ def approx(x: float, y: float=0.0, epsilon: float=APPROX) -> bool:
```
</details>
### ***def*** `sign(x: float, only_neg: bool) -> str`
### *def* `sign(x: float = False)`
获取数的符号。
Args:
参数:
x: 数
x: 数
only_neg: 是否只返回负数的符号
only_neg: 是否只返回负数的符号
Returns:
符号 + - ""
<details>
<summary></summary>
<summary>源码</summary>
```python
def sign(x: float, only_neg: bool=False) -> str:
@ -114,28 +103,24 @@ def sign(x: float, only_neg: bool=False) -> str:
```
</details>
### ***def*** `sign_format(x: float, only_neg: bool) -> str`
### *def* `sign_format(x: float = False)`
格式化符号数
-1 -> -1
1 -> +1
0 -> ""
Args:
参数:
x: 数
x: 数
only_neg: 是否只返回负数的符号
only_neg: 是否只返回负数的符号
Returns:
符号 + - ""
<details>
<summary></summary>
<summary>源码</summary>
```python
def sign_format(x: float, only_neg: bool=False) -> str:
@ -160,18 +145,11 @@ def sign_format(x: float, only_neg: bool=False) -> str:
### ***class*** `Approx`
用于近似比较对象
已实现对象 实数 Vector3 Point3 Plane3 Line3
### &emsp; ***def*** `__init__(self, value: RealNumber) -> None`
&emsp;
- #### *def* `__init__(self, value: RealNumber)`
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def __init__(self, value: RealNumber):
@ -179,12 +157,32 @@ def __init__(self, value: RealNumber):
```
</details>
### &emsp; ***def*** `raise_type_error(self, other: Any) -> None`
&emsp;
- #### *def* `__eq__(self, other)`
- #
<details>
<summary></summary>
<summary>源码</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>
- #### *def* `raise_type_error(self, other)`
- #
<details>
<summary>源码</summary>
```python
def raise_type_error(self, other):
@ -192,3 +190,15 @@ def raise_type_error(self, other):
```
</details>
- #### *def* `__ne__(self, other)`
- #
<details>
<summary>源码</summary>
```python
def __ne__(self, other):
return not self.__eq__(other)
```
</details>

View File

@ -1,28 +1,33 @@
---
title: mbcp.mp\nmath.vector
order: 1
icon: laptop-code
category: API
title: mbcp.mp_math.vector
---
### ***var*** `zero_vector3 = Vector3(0, 0, 0)`
### ***var*** `x_axis = Vector3(1, 0, 0)`
### ***var*** `y_axis = Vector3(0, 1, 0)`
### ***var*** `z_axis = Vector3(0, 0, 1)`
### ***class*** `Vector3`
- #### *def* `__init__(self, x: float, y: float, z: float)`
### &emsp; ***def*** `__init__(self, x: float, y: float, z: float) -> None`
3维向量
&emsp;3维向量
参数:
Args:
x: x轴分量
x: x轴分量
y: y轴分量
y: y轴分量
z: z轴分量
z: z轴分量
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def __init__(self, x: float, y: float, z: float):
@ -39,24 +44,21 @@ def __init__(self, x: float, y: float, z: float):
```
</details>
### &emsp; ***def*** `approx(self, other: 'Vector3', epsilon: float) -> bool`
&emsp;判断两个向量是否近似相等。
Args:
other:
epsilon:
- #### *def* `approx(self, other: 'Vector3', epsilon: float = APPROX)`
判断两个向量是否近似相等。
Returns:
参数:
是否近似相等
other:
epsilon:
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def approx(self, other: 'Vector3', epsilon: float=APPROX) -> bool:
@ -73,20 +75,19 @@ def approx(self, other: 'Vector3', epsilon: float=APPROX) -> bool:
```
</details>
### &emsp; ***def*** `cal_angle(self, other: 'Vector3') -> 'AnyAngle'`
- #### *def* `cal_angle(self, other: 'Vector3')`
&emsp;计算两个向量之间的夹角。
Args:
计算两个向量之间的夹角。
other: 另一个向量
参数:
Returns:
other: 另一个向量
夹角
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
def cal_angle(self, other: 'Vector3') -> 'AnyAngle':
@ -101,44 +102,19 @@ def cal_angle(self, other: 'Vector3') -> 'AnyAngle':
```
</details>
### &emsp; ***def*** `cross(self, other: 'Vector3') -> 'Vector3'`
&emsp;向量积 叉乘v1 cross v2 -> v3
- #### *def* `cross(self, other: 'Vector3')`
向量积 叉乘v1 cross v2 -> v3
叉乘为0则两向量平行。
其余结果的模为平行四边形的面积。
返回如下行列式的结果:
``i j k``
``x1 y1 z1``
``x2 y2 z2``
Args:
other:
Returns:
行列式的结果
- #
<details>
<summary>源代码</summary>
<summary>源码</summary>
```python
def cross(self, other: 'Vector3') -> 'Vector3':
@ -165,22 +141,21 @@ def cross(self, other: 'Vector3') -> 'Vector3':
```
</details>
### &emsp; ***def*** `is_approx_parallel(self, other: 'Vector3', epsilon: float) -> bool`
- #### *def* `is_approx_parallel(self, other: 'Vector3', epsilon: float = APPROX)`
&emsp;判断两个向量是否近似平行。
Args:
判断两个向量是否近似平行。
other: 另一个向量
参数:
epsilon: 允许的误差
other: 另一个向量
Returns:
epsilon: 允许的误差
是否近似平行
- #
<details>
<summary>源代码</summary>
<summary>源码</summary>
```python
def is_approx_parallel(self, other: 'Vector3', epsilon: float=APPROX) -> bool:
@ -196,20 +171,19 @@ def is_approx_parallel(self, other: 'Vector3', epsilon: float=APPROX) -> bool:
```
</details>
### &emsp; ***def*** `is_parallel(self, other: 'Vector3') -> bool`
- #### *def* `is_parallel(self, other: 'Vector3')`
&emsp;判断两个向量是否平行。
Args:
判断两个向量是否平行。
other: 另一个向量
参数:
Returns:
other: 另一个向量
是否平行
- #
<details>
<summary>源代码</summary>
<summary>源码</summary>
```python
def is_parallel(self, other: 'Vector3') -> bool:
@ -224,16 +198,17 @@ def is_parallel(self, other: 'Vector3') -> bool:
```
</details>
### &emsp; ***def*** `normalize(self) -> None`
&emsp;将向量归一化。
- #### *def* `normalize(self)`
将向量归一化。
自体归一化,不返回值。
- #
<details>
<summary>源代码</summary>
<summary>源码</summary>
```python
def normalize(self):
@ -249,15 +224,16 @@ def normalize(self):
```
</details>
### &emsp; ***@property***
### &emsp; ***def*** `np_array(self: Any) -> 'np.ndarray'`
- #### `@property`
- #### *def* `np_array(self)`
&emsp;返回numpy数组
Returns:
- #
<details>
<summary>源代码</summary>
<summary>源码</summary>
```python
@property
@ -270,17 +246,20 @@ def np_array(self) -> 'np.ndarray':
```
</details>
### &emsp; ***@property***
### &emsp; ***def*** `length(self: Any) -> float`
- #### `@property`
- #### *def* `length(self)`
&emsp;向量的模。
Returns:
向量的模。
返回:
- #
<details>
<summary>源代码</summary>
<summary>源码</summary>
```python
@property
@ -294,17 +273,20 @@ def length(self) -> float:
```
</details>
### &emsp; ***@property***
### &emsp; ***def*** `unit(self: Any) -> 'Vector3'`
- #### `@property`
- #### *def* `unit(self)`
&emsp;获取该向量的单位向量。
Returns:
获取该向量的单位向量。
单位向量
返回:
单位向量
- #
<details>
<summary>源代码</summary>
<summary>源码</summary>
```python
@property
@ -318,23 +300,372 @@ def unit(self) -> 'Vector3':
```
</details>
### ***var*** `zero_vector3 = Vector3(0, 0, 0)`
- #### *def* `__abs__(self)`
- #
<details>
<summary>源码</summary>
```python
def __abs__(self):
return self.length
```
</details>
- #### `@overload`
- #### *def* `__add__(self, other: 'Vector3')`
- #
<details>
<summary>源码</summary>
```python
@overload
def __add__(self, other: 'Vector3') -> 'Vector3':
...
```
</details>
- #### `@overload`
- #### *def* `__add__(self, other: 'Point3')`
- #
<details>
<summary>源码</summary>
```python
@overload
def __add__(self, other: 'Point3') -> 'Point3':
...
```
</details>
- #### *def* `__add__(self, other)`
V + P -> P
### ***var*** `x_axis = Vector3(1, 0, 0)`
V + V -> V
参数:
other:
- #
<details>
<summary>源码</summary>
### ***var*** `y_axis = Vector3(0, 1, 0)`
```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>
- #### *def* `__eq__(self, other)`
判断两个向量是否相等。
### ***var*** `z_axis = Vector3(0, 0, 1)`
参数:
other:
- #
<details>
<summary>源码</summary>
### ***var*** `length = self.length`
```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>
- #### *def* `__radd__(self, other: 'Point3')`
P + V -> P
别去点那边实现了。
:param other:
:return:
- #
<details>
<summary>源码</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`
- #### *def* `__sub__(self, other: 'Vector3')`
- #
<details>
<summary>源码</summary>
```python
@overload
def __sub__(self, other: 'Vector3') -> 'Vector3':
...
```
</details>
- #### `@overload`
- #### *def* `__sub__(self, other: 'Point3')`
- #
<details>
<summary>源码</summary>
```python
@overload
def __sub__(self, other: 'Point3') -> 'Point3':
...
```
</details>
- #### *def* `__sub__(self, other)`
V - P -> P
V - V -> V
参数:
other:
- #
<details>
<summary>源码</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>
- #### *def* `__rsub__(self, other: 'Point3')`
P - V -> P
参数:
other:
- #
<details>
<summary>源码</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`
- #### *def* `__mul__(self, other: 'Vector3')`
- #
<details>
<summary>源码</summary>
```python
@overload
def __mul__(self, other: 'Vector3') -> 'Vector3':
...
```
</details>
- #### `@overload`
- #### *def* `__mul__(self, other: RealNumber)`
- #
<details>
<summary>源码</summary>
```python
@overload
def __mul__(self, other: RealNumber) -> 'Vector3':
...
```
</details>
- #### *def* `__mul__(self, other: 'int | float | Vector3')`
数组运算 非点乘。点乘使用@叉乘使用cross。
参数:
other:
- #
<details>
<summary>源码</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>
- #### *def* `__rmul__(self, other: 'RealNumber')`
- #
<details>
<summary>源码</summary>
```python
def __rmul__(self, other: 'RealNumber') -> 'Vector3':
return self.__mul__(other)
```
</details>
- #### *def* `__matmul__(self, other: 'Vector3')`
点乘。
参数:
other:
- #
<details>
<summary>源码</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>
- #### *def* `__truediv__(self, other: RealNumber)`
- #
<details>
<summary>源码</summary>
```python
def __truediv__(self, other: RealNumber) -> 'Vector3':
return Vector3(self.x / other, self.y / other, self.z / other)
```
</details>
- #### *def* `__neg__(self)`
- #
<details>
<summary>源码</summary>
```python
def __neg__(self):
return Vector3(-self.x, -self.y, -self.z)
```
</details>
- #### *def* `__repr__(self)`
- #
<details>
<summary>源码</summary>
```python
def __repr__(self):
return f'Vector3({self.x}, {self.y}, {self.z})'
```
</details>
- #### *def* `__str__(self)`
- #
<details>
<summary>源码</summary>
```python
def __str__(self):
return f'Vector3({self.x}, {self.y}, {self.z})'
```
</details>

View File

@ -1,7 +1,3 @@
---
title: mbcp.particle.\n\ninit\n\n
order: 1
icon: laptop-code
category: API
title: mbcp.particle
---

View File

@ -1,7 +1,3 @@
---
title: mbcp.presets.\n\ninit\n\n
order: 1
icon: laptop-code
category: API
title: mbcp.presets
---

View File

@ -1,26 +1,24 @@
---
title: mbcp.presets.model.\n\ninit\n\n
order: 1
icon: laptop-code
category: API
title: mbcp.presets.model
---
### ***class*** `GeometricModels`
- #### `@staticmethod`
- #### *def* `sphere(radius: float, density: float)`
### ***def*** `sphere(radius: float, density: float) -> None`
生成球体上的点集。
Args:
参数:
radius:
radius:
density:
density:
Returns:
List[Point3]: 球体上的点集。
- #
<details>
<summary></summary>
<summary>源码</summary>
```python
@staticmethod
@ -44,75 +42,3 @@ def sphere(radius: float, density: float):
```
</details>
### ***class*** `GeometricModels`
### &emsp; ***@staticmethod***
### &emsp; ***def*** `sphere(radius: float, density: float) -> None`
&emsp;生成球体上的点集。
Args:
radius:
density:
Returns:
List[Point3]: 球体上的点集。
<details>
<summary>源代码</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>
### ***var*** `area = 4 * np.pi * radius ** 2`
### ***var*** `num = int(area * density)`
### ***var*** `phi_list = np.arccos([clamp(-1 + (2.0 * _ - 1.0) / num, -1, 1) for _ in range(num)])`
### ***var*** `theta_list = np.sqrt(num * np.pi) * phi_list`
### ***var*** `x_array = radius * np.sin(phi_list) * np.cos(theta_list)`
### ***var*** `y_array = radius * np.sin(phi_list) * np.sin(theta_list)`
### ***var*** `z_array = radius * np.cos(phi_list)`