Hi everyone! ![]()
I’m new to the Mojo community and wanted to share my first project - a QuickHull3D implementation that achieves performance close to the C++ QHull library.
## What I Built
I’ve implemented the QuickHull3D algorithm for convex hull generation from 3D point sets in Mojo. The implementation includes:
- **Full QuickHull3D algorithm** with support for both f32 and f64 precision
- **Custom data structures**: Vector3d, Vertex, HalfEdge, Face, FaceList, VertexList
- **Memory pool** for efficient memory management
- **Waterman polyhedron coordinate generation** - produces sphere-like point distributions based on integer lattice points
- **Python bindings** with NumPy integration for easy use from Python
- **OpenGL viewer** for interactive 3D visualization
## Performance
After benchmarking against the C++ QHull library, my Mojo implementation achieves near-equivalent performance. The key optimizations include:
- Custom memory pool to reduce allocation overhead
- Efficient data structures with pointer-based linked lists
- Careful tolerance handling for numerical stability
- Support for both float32 and float64 precision
## Code Structure
The implementation is organized across several modules:
- `quickhull3d.mojo` - Main QuickHull3D algorithm
- `waterman.mojo` - Waterman polyhedron coordinate generation
- `vector3d.mojo`, `vertex.mojo`, `halfedge.mojo`, `face.mojo` - Core data structures
- `facelist.mojo`, `vertexlist.mojo`, `mempool.mojo` - Supporting structures
- Python bindings via `PyInit_waterman()` for NumPy integration
## Example Usage
```mojo
var q = QuickHull3D[DType.float32](watermancoords[DType.float32](5.0))
q.buildHull()
var faces = q.getFaces()
var vertices = q.getVertices()
```
Or from Python:
```python
import waterman
faces, vertices, colors = waterman.waterman_qhull(5.0)
```
available @ GitHub - rforcen/mojo: mojo lang. code · GitHub