https://github.com/evanw/polyfrag
Geometry library that splits polyhedra using 3D planes
https://github.com/evanw/polyfrag
Last synced: 3 months ago
JSON representation
Geometry library that splits polyhedra using 3D planes
- Host: GitHub
- URL: https://github.com/evanw/polyfrag
- Owner: evanw
- License: mit
- Created: 2010-12-12T08:16:43.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2011-11-05T22:49:34.000Z (over 13 years ago)
- Last Synced: 2025-03-17T12:02:07.380Z (3 months ago)
- Language: C++
- Homepage:
- Size: 698 KB
- Stars: 38
- Watchers: 5
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This library contains a stable algorithm for splitting a convex polyhedron
into two pieces on either side of a 3D plane. It is useful for generating
polyhedron fragments to make a polyhedron look like it's breaking apart.

Example usage:
srand(1);
std::vector polyhedra;
Polyhedron::recursiveSlice(Polyhedron::box(Vector3D(-0.5, -2, -0.5), Vector3D(0.5, 2, 0.5)), polyhedra, 4);for (int i = 0; i < polyhedra.size(); i++)
{
Vector3D offset = polyhedra[i]->getCentroid() * 0.5;
glPushMatrix();
glTranslatef(offset.x, offset.y, offset.z);
polyhedra[i]->draw();
glPopMatrix();
delete polyhedra[i];
}The generated mesh for a polyhedron uses a shared set of vertices which each
polygon indexes into. All polygons are generated in counterclockwise order.