2024-08-28 10:52:17 +08:00
|
|
|
|
---
|
2024-08-28 12:02:30 +08:00
|
|
|
|
title: mbcp.mp_math.angle
|
2024-08-28 10:52:17 +08:00
|
|
|
|
---
|
2024-08-28 22:07:43 +08:00
|
|
|
|
### **class** `Angle`
|
|
|
|
|
### **class** `AnyAngle(Angle)`
|
|
|
|
|
### *method* `__init__(self, value: float, is_radian: bool = False)`
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**说明**: 任意角度。
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**参数**:
|
|
|
|
|
> - value: 角度或弧度值
|
|
|
|
|
> - is_radian: 是否为弧度,默认为否
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<details>
|
2024-08-29 13:46:59 +08:00
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
```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>
|
|
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
|
### `@property`
|
2024-08-28 22:07:43 +08:00
|
|
|
|
### *method* `complementary(self) -> AnyAngle`
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**说明**: 余角:两角的和为90°。
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**返回**: 余角
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
|
2024-08-28 10:52:17 +08:00
|
|
|
|
<details>
|
2024-08-29 13:46:59 +08:00
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
@property
|
|
|
|
|
def complementary(self) -> 'AnyAngle':
|
|
|
|
|
"""
|
|
|
|
|
余角:两角的和为90°。
|
|
|
|
|
Returns:
|
|
|
|
|
余角
|
|
|
|
|
"""
|
|
|
|
|
return AnyAngle(PI / 2 - self.minimum_positive.radian, is_radian=True)
|
|
|
|
|
```
|
|
|
|
|
</details>
|
|
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
|
### `@property`
|
2024-08-28 22:07:43 +08:00
|
|
|
|
### *method* `supplementary(self) -> AnyAngle`
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**说明**: 补角:两角的和为180°。
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**返回**: 补角
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
2024-08-28 10:52:17 +08:00
|
|
|
|
<details>
|
2024-08-29 13:46:59 +08:00
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
@property
|
|
|
|
|
def supplementary(self) -> 'AnyAngle':
|
|
|
|
|
"""
|
|
|
|
|
补角:两角的和为180°。
|
|
|
|
|
Returns:
|
|
|
|
|
补角
|
|
|
|
|
"""
|
|
|
|
|
return AnyAngle(PI - self.minimum_positive.radian, is_radian=True)
|
|
|
|
|
```
|
|
|
|
|
</details>
|
|
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
|
### `@property`
|
2024-08-28 22:07:43 +08:00
|
|
|
|
### *method* `degree(self) -> float`
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**说明**: 角度。
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**返回**: 弧度
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<details>
|
2024-08-29 13:46:59 +08:00
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
@property
|
|
|
|
|
def degree(self) -> float:
|
|
|
|
|
"""
|
|
|
|
|
角度。
|
|
|
|
|
Returns:
|
|
|
|
|
弧度
|
|
|
|
|
"""
|
|
|
|
|
return self.radian * 180 / PI
|
|
|
|
|
```
|
|
|
|
|
</details>
|
|
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
|
### `@property`
|
2024-08-28 22:07:43 +08:00
|
|
|
|
### *method* `minimum_positive(self) -> AnyAngle`
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**说明**: 最小正角。
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**返回**: 最小正角度
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
|
2024-08-28 10:52:17 +08:00
|
|
|
|
<details>
|
2024-08-29 13:46:59 +08:00
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
@property
|
|
|
|
|
def minimum_positive(self) -> 'AnyAngle':
|
|
|
|
|
"""
|
|
|
|
|
最小正角。
|
|
|
|
|
Returns:
|
|
|
|
|
最小正角度
|
|
|
|
|
"""
|
|
|
|
|
return AnyAngle(self.radian % (2 * PI))
|
|
|
|
|
```
|
|
|
|
|
</details>
|
|
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
|
### `@property`
|
2024-08-28 22:07:43 +08:00
|
|
|
|
### *method* `maximum_negative(self) -> AnyAngle`
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**说明**: 最大负角。
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**返回**: 最大负角度
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
2024-08-28 10:52:17 +08:00
|
|
|
|
<details>
|
2024-08-29 13:46:59 +08:00
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
@property
|
|
|
|
|
def maximum_negative(self) -> 'AnyAngle':
|
|
|
|
|
"""
|
|
|
|
|
最大负角。
|
|
|
|
|
Returns:
|
|
|
|
|
最大负角度
|
|
|
|
|
"""
|
|
|
|
|
return AnyAngle(-self.radian % (2 * PI), is_radian=True)
|
|
|
|
|
```
|
|
|
|
|
</details>
|
|
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
|
### `@property`
|
2024-08-28 22:07:43 +08:00
|
|
|
|
### *method* `sin(self) -> float`
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**说明**: 正弦值。
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**返回**: 正弦值
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
2024-08-28 10:52:17 +08:00
|
|
|
|
<details>
|
2024-08-29 13:46:59 +08:00
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
@property
|
|
|
|
|
def sin(self) -> float:
|
|
|
|
|
"""
|
|
|
|
|
正弦值。
|
|
|
|
|
Returns:
|
|
|
|
|
正弦值
|
|
|
|
|
"""
|
|
|
|
|
return math.sin(self.radian)
|
|
|
|
|
```
|
|
|
|
|
</details>
|
|
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
|
### `@property`
|
2024-08-28 22:07:43 +08:00
|
|
|
|
### *method* `cos(self) -> float`
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**说明**: 余弦值。
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**返回**: 余弦值
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<details>
|
2024-08-29 13:46:59 +08:00
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
@property
|
|
|
|
|
def cos(self) -> float:
|
|
|
|
|
"""
|
|
|
|
|
余弦值。
|
|
|
|
|
Returns:
|
|
|
|
|
余弦值
|
|
|
|
|
"""
|
|
|
|
|
return math.cos(self.radian)
|
|
|
|
|
```
|
|
|
|
|
</details>
|
|
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
|
### `@property`
|
2024-08-28 22:07:43 +08:00
|
|
|
|
### *method* `tan(self) -> float`
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**说明**: 正切值。
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**返回**: 正切值
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
|
2024-08-28 10:52:17 +08:00
|
|
|
|
<details>
|
2024-08-29 13:46:59 +08:00
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
@property
|
|
|
|
|
def tan(self) -> float:
|
|
|
|
|
"""
|
|
|
|
|
正切值。
|
|
|
|
|
Returns:
|
|
|
|
|
正切值
|
|
|
|
|
"""
|
|
|
|
|
return math.tan(self.radian)
|
|
|
|
|
```
|
|
|
|
|
</details>
|
|
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
|
### `@property`
|
2024-08-28 22:07:43 +08:00
|
|
|
|
### *method* `cot(self) -> float`
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**说明**: 余切值。
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**返回**: 余切值
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
2024-08-28 10:52:17 +08:00
|
|
|
|
<details>
|
2024-08-29 13:46:59 +08:00
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
@property
|
|
|
|
|
def cot(self) -> float:
|
|
|
|
|
"""
|
|
|
|
|
余切值。
|
|
|
|
|
Returns:
|
|
|
|
|
余切值
|
|
|
|
|
"""
|
|
|
|
|
return 1 / math.tan(self.radian)
|
|
|
|
|
```
|
|
|
|
|
</details>
|
|
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
|
### `@property`
|
2024-08-28 22:07:43 +08:00
|
|
|
|
### *method* `sec(self) -> float`
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**说明**: 正割值。
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**返回**: 正割值
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<details>
|
2024-08-29 13:46:59 +08:00
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
@property
|
|
|
|
|
def sec(self) -> float:
|
|
|
|
|
"""
|
|
|
|
|
正割值。
|
|
|
|
|
Returns:
|
|
|
|
|
正割值
|
|
|
|
|
"""
|
|
|
|
|
return 1 / math.cos(self.radian)
|
|
|
|
|
```
|
|
|
|
|
</details>
|
|
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
|
### `@property`
|
2024-08-28 22:07:43 +08:00
|
|
|
|
### *method* `csc(self) -> float`
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**说明**: 余割值。
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
2024-08-29 13:46:59 +08:00
|
|
|
|
**返回**: 余割值
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<details>
|
2024-08-29 13:46:59 +08:00
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
@property
|
|
|
|
|
def csc(self) -> float:
|
|
|
|
|
"""
|
|
|
|
|
余割值。
|
|
|
|
|
Returns:
|
|
|
|
|
余割值
|
|
|
|
|
"""
|
|
|
|
|
return 1 / math.sin(self.radian)
|
|
|
|
|
```
|
|
|
|
|
</details>
|
|
|
|
|
|
2024-08-28 22:07:43 +08:00
|
|
|
|
### *method* `self + other: AnyAngle => AnyAngle`
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
<details>
|
2024-08-29 13:46:59 +08:00
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
def __add__(self, other: 'AnyAngle') -> 'AnyAngle':
|
|
|
|
|
return AnyAngle(self.radian + other.radian, is_radian=True)
|
|
|
|
|
```
|
|
|
|
|
</details>
|
|
|
|
|
|
2024-08-28 22:07:43 +08:00
|
|
|
|
### *method* `__eq__(self, other)`
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
<details>
|
2024-08-29 13:46:59 +08:00
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
def __eq__(self, other):
|
|
|
|
|
return approx(self.radian, other.radian)
|
|
|
|
|
```
|
|
|
|
|
</details>
|
|
|
|
|
|
2024-08-28 22:07:43 +08:00
|
|
|
|
### *method* `self - other: AnyAngle => AnyAngle`
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
<details>
|
2024-08-29 13:46:59 +08:00
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
def __sub__(self, other: 'AnyAngle') -> 'AnyAngle':
|
|
|
|
|
return AnyAngle(self.radian - other.radian, is_radian=True)
|
|
|
|
|
```
|
|
|
|
|
</details>
|
|
|
|
|
|
2024-08-28 22:07:43 +08:00
|
|
|
|
### *method* `self * other: float => AnyAngle`
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
<details>
|
2024-08-29 13:46:59 +08:00
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
def __mul__(self, other: float) -> 'AnyAngle':
|
|
|
|
|
return AnyAngle(self.radian * other, is_radian=True)
|
|
|
|
|
```
|
|
|
|
|
</details>
|
|
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
|
### `@overload`
|
2024-08-28 22:07:43 +08:00
|
|
|
|
### *method* `self / other: float => AnyAngle`
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
<details>
|
2024-08-29 13:46:59 +08:00
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
@overload
|
|
|
|
|
def __truediv__(self, other: float) -> 'AnyAngle':
|
|
|
|
|
...
|
|
|
|
|
```
|
|
|
|
|
</details>
|
|
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
|
### `@overload`
|
2024-08-28 22:07:43 +08:00
|
|
|
|
### *method* `self / other: AnyAngle => float`
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
<details>
|
2024-08-29 13:46:59 +08:00
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
@overload
|
|
|
|
|
def __truediv__(self, other: 'AnyAngle') -> float:
|
|
|
|
|
...
|
|
|
|
|
```
|
|
|
|
|
</details>
|
|
|
|
|
|
2024-08-28 22:07:43 +08:00
|
|
|
|
### *method* `self / other`
|
2024-08-28 21:27:52 +08:00
|
|
|
|
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
<details>
|
2024-08-29 13:46:59 +08:00
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-28 12:02:30 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
def __truediv__(self, other):
|
|
|
|
|
if isinstance(other, AnyAngle):
|
|
|
|
|
return self.radian / other.radian
|
|
|
|
|
return AnyAngle(self.radian / other, is_radian=True)
|
|
|
|
|
```
|
|
|
|
|
</details>
|
|
|
|
|
|