petrify: a programmatic cad library¶
petrify can be used to create open-source programmatic and parametric three-dimensional models.
Example usage:
from petrify import u, Point, Vector
from petrify.formats import STL
from petrify.solid import Box
big = Box(Point(0, 0, 0), Vector(1, 1, 1))
small = Box(Point(0.5, 0.5, 0.5), Vector(0.5, 0.5, 0.5))
STL('example.stl', 'mm').write((big - small).as_unit('in'))
Generics¶
Object creation often requires switching between 2D and 3D descriptions. For
that reason, we encourage you to use the Point
, Vector
, and
Polygon
definitions exported from the top-level petrify
package.
These objects automatically construct the “correct” representation from
petrify.space
or petrify.plane
in context:
>>> from petrify import Point, Vector, Polygon
>>> Point(1, 2, 3)
Point(1, 2, 3)
>>> Vector(1, 2)
Vector(1, 2)
>>> Polygon([Point(0, 0), Point(2, 0), Point(1, 1)])
Polygon([Point(0, 0), Point(2, 0), Point(1, 1)])
>>> Polygon([Point(0, 0, 0), Point(2, 0, 1), Point(1, 1, -1)])
Polygon([Point(0, 0, 0), Point(2, 0, 1), Point(1, 1, -1)])