2024-08-28 10:52:17 +08:00
|
|
|
---
|
2024-08-28 12:02:30 +08:00
|
|
|
title: mbcp.presets.model
|
2024-08-28 10:52:17 +08:00
|
|
|
---
|
2024-08-28 22:07:43 +08:00
|
|
|
### **class** `GeometricModels`
|
2024-08-28 21:27:52 +08:00
|
|
|
### `@staticmethod`
|
2024-08-28 22:07:43 +08:00
|
|
|
### *method* `sphere(radius: float, density: float)`
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
2024-08-28 12:02:30 +08:00
|
|
|
生成球体上的点集。
|
2024-08-28 10:52:17 +08:00
|
|
|
|
2024-08-28 22:07:43 +08:00
|
|
|
**参数**:
|
2024-08-28 10:52:17 +08:00
|
|
|
|
2024-08-28 21:27:52 +08:00
|
|
|
- radius:
|
|
|
|
|
|
|
|
- density:
|
2024-08-28 10:52:17 +08:00
|
|
|
|
2024-08-28 22:07:43 +08:00
|
|
|
**返回**:
|
|
|
|
|
|
|
|
- List[Point3]: 球体上的点集。
|
|
|
|
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
<details>
|
2024-08-28 22:07:43 +08:00
|
|
|
<summary> <i>源代码</i> </summary>
|
2024-08-28 10:52:17 +08:00
|
|
|
|
|
|
|
```python
|
|
|
|
@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>
|
|
|
|
|