mbcp/docs/api/mp_math/segment.md

60 lines
968 B
Markdown
Raw Normal View History

2024-08-28 10:52:17 +08:00
---
2024-08-28 12:02:30 +08:00
title: mbcp.mp_math.segment
2024-08-28 10:52:17 +08:00
---
### ***class*** `Segment3`
2024-08-28 21:27:52 +08:00
### *def* `__init__(self, p1: 'Point3', p2: 'Point3')`
2024-08-28 10:52:17 +08:00
2024-08-28 12:02:30 +08:00
三维空间中的线段。
2024-08-28 10:52:17 +08:00
:param p1:
:param p2:
2024-08-28 12:02:30 +08:00
2024-08-28 21:27:52 +08:00
2024-08-28 10:52:17 +08:00
<details>
2024-08-28 12:02:30 +08:00
<summary>源码</summary>
2024-08-28 10:52:17 +08:00
```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>
2024-08-28 21:27:52 +08:00
### *def* `__repr__(self)`
2024-08-28 12:02:30 +08:00
<details>
<summary>源码</summary>
```python
def __repr__(self):
return f'Segment3({self.p1}, {self.p2})'
```
</details>
2024-08-28 21:27:52 +08:00
### *def* `__str__(self)`
2024-08-28 12:02:30 +08:00
<details>
<summary>源码</summary>
```python
def __str__(self):
return f'Segment3({self.p1} -> {self.p2})'
```
</details>