Object Construction

Creation of complex objects from humble building blocks:

Box :
A simple box.
Cylinder :
A cylinder rotated around an origin and axis.
Sphere :
A sphere centered around a given point.
PolygonExtrusion :
Extrusion of a PlanarPolygon into a three-dimensional shape.
Spun :
A series of profiles spun around an axis and connected together.
Extrusion :
Complex layered objects with polygon slices.
Node :
Arbitrary construction of geometry via polygons.

All of the above classes subclass Node, which allows object joining via CSG union and difference operations.

class petrify.solid.Basis(origin, bx, by)[source]

Bases: object

Embeds a two-dimensional space into a three-dimensional space:

>>> basis = Basis(Point(1, 0, 0), Vector.basis.y, Vector.basis.z)
>>> basis.project(Point2(2, 3))
Point(1, 2, 3)
>>> basis.project(Vector2(-2, -3))
Vector(1, -2, -3)

Can be translated:

>>> translated = basis.xy + Vector(0, 0, 2)
>>> translated
Basis(Point(0, 0, 2), Vector(1, 0, 0), Vector(0, 1, 0))
>>> translated.project(Point2(2, 3))
Point(2, 3, 2)

Note

Any given Plane has an infinite number of associated Basis constructions.

There are special Basis objects for commonly used bases:

>>> Basis.unit
Basis(Point(0, 0, 0), Vector(1, 0, 0), Vector(0, 1, 0))
>>> Basis.xy
Basis(Point(0, 0, 0), Vector(1, 0, 0), Vector(0, 1, 0))
>>> Basis.yz
Basis(Point(0, 0, 0), Vector(0, 1, 0), Vector(0, 0, 1))
>>> Basis.xz
Basis(Point(0, 0, 0), Vector(1, 0, 0), Vector(0, 0, 1))
grid(ticks, count)[source]

Returns a visual petrify.visualize.Grid of the projected space.

class petrify.solid.Box(origin, size)[source]

Bases: petrify.solid.Extrusion

A simple three-dimensional box:

>>> cube = Box(Point.origin, Vector(1, 1, 1))
origin :
a Point defining the origin of this box.
size :
a Vector of the box’s size.
as_unit(unit)

Declare a unit for unitless geometry:

>>> Box(Point(0, 0, 0), Vector(1, 1, 1)).as_unit('inch').units
<Unit('inch')>
centered(point)

Center this node at the given point:

>>> b = Box(Point(0, 0, 0), Vector(2, 2, 2))
>>> b.centered(Point.origin).envelope()
Box(Point(-1.0, -1.0, -1.0), Vector(2.0, 2.0, 2.0))
envelope()

Returns the axis-aligned bounding box for this shape:

>>> parallelogram = Polygon([
...     Point(0, 0),
...     Point(0, 1),
...     Point(1, 2),
...     Point(1, 1)
... ])
>>> extruded = PolygonExtrusion(
...     PlanarPolygon(Basis.xy, parallelogram),
...     Vector(0, 0, 1)
... )
>>> extruded.envelope()
Box(Point(0, 0, 0), Vector(1, 2, 1))
generate_polygons()

Calculates all polygons for this shape.

render(**properties)

Create a pythreejs visualization of this geometry for use in interactive notebooks.

ring(bottom, top)

Builds a ring from two slices.

rotate(axis, theta)

Rotate this geometry around the given axis vector by theta radians.

rotate_at(origin, axis, theta)

Rotate this geometry about the given origin and axis by theta radians.

scale(scale)

Scale this geometry by the provided scale vector.

translate(delta)

Translate this geometry by the provided translate vector.

class petrify.solid.Collection(nodes)[source]

Bases: petrify.solid.Node

Collection of multiple objects. Self-intersection is unsupported, but lack of intersection is not enforced:

>>> c = Collection([
...     Box(Point.origin, Vector(1, 1, 1)),
...     Box(Point(0, 5, 0), Vector(1, 1, 1))
... ])
as_unit(unit)

Declare a unit for unitless geometry:

>>> Box(Point(0, 0, 0), Vector(1, 1, 1)).as_unit('inch').units
<Unit('inch')>
centered(point)

Center this node at the given point:

>>> b = Box(Point(0, 0, 0), Vector(2, 2, 2))
>>> b.centered(Point.origin).envelope()
Box(Point(-1.0, -1.0, -1.0), Vector(2.0, 2.0, 2.0))
envelope()

Returns the axis-aligned bounding box for this shape:

>>> parallelogram = Polygon([
...     Point(0, 0),
...     Point(0, 1),
...     Point(1, 2),
...     Point(1, 1)
... ])
>>> extruded = PolygonExtrusion(
...     PlanarPolygon(Basis.xy, parallelogram),
...     Vector(0, 0, 1)
... )
>>> extruded.envelope()
Box(Point(0, 0, 0), Vector(1, 2, 1))
render(**properties)[source]

Create a pythreejs visualization of this geometry for use in interactive notebooks.

rotate(axis, theta)[source]

Rotate this geometry around the given axis vector by theta radians.

rotate_at(origin, axis, theta)[source]

Rotate this geometry about the given origin and axis by theta radians.

scale(scale)[source]

Scale this geometry by the provided scale vector.

translate(delta)[source]

Translate this geometry by the provided translate vector.

class petrify.solid.Cylinder(origin, axis, radius, segments=10)[source]

Bases: petrify.solid.PolygonExtrusion

A three-dimensional cylinder extruded along the given axis:

>>> axle = Cylinder(Point.origin, Vector.basis.y * 10, 1.0)

The actual cylinder is approximated by creating many segments of quads to simulate a circular shape.

origin :
a Point defining the origin of this cylinder.
axis :
a Vector that defines the axis the cylinder will be “spun about”. The magnitude of the axis is the height of the cylinder.
radius :
the radius of the cylinder.
segments :
the number of quads to use when approximating the cylinder.
as_unit(unit)

Declare a unit for unitless geometry:

>>> Box(Point(0, 0, 0), Vector(1, 1, 1)).as_unit('inch').units
<Unit('inch')>
centered(point)

Center this node at the given point:

>>> b = Box(Point(0, 0, 0), Vector(2, 2, 2))
>>> b.centered(Point.origin).envelope()
Box(Point(-1.0, -1.0, -1.0), Vector(2.0, 2.0, 2.0))
envelope()

Returns the axis-aligned bounding box for this shape:

>>> parallelogram = Polygon([
...     Point(0, 0),
...     Point(0, 1),
...     Point(1, 2),
...     Point(1, 1)
... ])
>>> extruded = PolygonExtrusion(
...     PlanarPolygon(Basis.xy, parallelogram),
...     Vector(0, 0, 1)
... )
>>> extruded.envelope()
Box(Point(0, 0, 0), Vector(1, 2, 1))
generate_polygons()

Calculates all polygons for this shape.

height()[source]

The height of this cylinder along its axis.

render(**properties)

Create a pythreejs visualization of this geometry for use in interactive notebooks.

ring(bottom, top)

Builds a ring from two slices.

rotate(axis, theta)

Rotate this geometry around the given axis vector by theta radians.

rotate_at(origin, axis, theta)

Rotate this geometry about the given origin and axis by theta radians.

scale(scale)

Scale this geometry by the provided scale vector.

translate(delta)

Translate this geometry by the provided translate vector.

class petrify.solid.Extrusion(slices)[source]

Bases: petrify.solid.Node

A three-dimensional object built from rings of PlanarPolygon objects with the same number of points at each ring:

>>> parallelogram = Polygon([
...    Point(0, 0),
...    Point(0, 1),
...    Point(1, 2),
...    Point(1, 1)
... ])
>>> square = Polygon([
...     Point(0, 0),
...     Point(0, 1),
...     Point(1, 1),
...     Point(1, 0)
... ])
>>> object = Extrusion([
...     PlanarPolygon(Basis.xy, parallelogram),
...     PlanarPolygon(Basis.xy + Vector(0, 0, 1), square),
... ])

The rings must all have the same number of vertices. Quads are generated to connect each ring, and the bottom and top layers then complete the shape.

rings :
A list of PlanarPolygon objects defining each ring of the final shape.
as_unit(unit)

Declare a unit for unitless geometry:

>>> Box(Point(0, 0, 0), Vector(1, 1, 1)).as_unit('inch').units
<Unit('inch')>
centered(point)

Center this node at the given point:

>>> b = Box(Point(0, 0, 0), Vector(2, 2, 2))
>>> b.centered(Point.origin).envelope()
Box(Point(-1.0, -1.0, -1.0), Vector(2.0, 2.0, 2.0))
envelope()

Returns the axis-aligned bounding box for this shape:

>>> parallelogram = Polygon([
...     Point(0, 0),
...     Point(0, 1),
...     Point(1, 2),
...     Point(1, 1)
... ])
>>> extruded = PolygonExtrusion(
...     PlanarPolygon(Basis.xy, parallelogram),
...     Vector(0, 0, 1)
... )
>>> extruded.envelope()
Box(Point(0, 0, 0), Vector(1, 2, 1))
generate_polygons()[source]

Calculates all polygons for this shape.

render(**properties)

Create a pythreejs visualization of this geometry for use in interactive notebooks.

ring(bottom, top)[source]

Builds a ring from two slices.

rotate(axis, theta)

Rotate this geometry around the given axis vector by theta radians.

rotate_at(origin, axis, theta)

Rotate this geometry about the given origin and axis by theta radians.

scale(scale)

Scale this geometry by the provided scale vector.

translate(delta)

Translate this geometry by the provided translate vector.

class petrify.solid.Face(basis, direction, polygon)[source]

Bases: petrify.space.PlanarPolygon

A PlanarPolygon with an associated polarity. Face.Positive polarity follows the right hand rule, Face.Negative is inverted.

>>> tri= Polygon2([Point2(0, 0), Point2(0, 2), Point2(1, 1)])
>>> triangle = Face(Basis.xy, Face.Positive, tri)
render()

Visualize this polygon in a Jupyter notebook.

petrify.solid.Matrix

alias of petrify.space.transform.Matrix3

class petrify.solid.Node(polygons)[source]

Bases: object

Convenience class for performing CSG operations on geometry.

All instances of this class can be added and subtracted via the built-in __add__ and __sub__ methods:

>>> a = Box(Point(0, 0, 0), Vector(1, 1, 1))
>>> b = Box(Point(0, 0, 0.5), Vector(1, 1, 1))
>>> union = a + b
>>> difference = a - b

All nodes also support scaling and translation via vectors:

>>> box = Box(Point(0, 0, 0), Vector(1, 1, 1))
>>> (box * Vector(2, 1, 1)).envelope()
Box(Point(0, 0, 0), Vector(2, 1, 1))
>>> (box + Vector(1, 0, 1)).envelope()
Box(Point(1.0, 0.0, 1.0), Vector(1.0, 1.0, 1.0))

To support unit operations via pint, multiplication and division by a scalar are also supported:

>>> (box * 2).envelope()
Box(Point(0, 0, 0), Vector(2, 2, 2))
>>> (box / 2).envelope()
Box(Point(0.0, 0.0, 0.0), Vector(0.5, 0.5, 0.5))
>>> from petrify import u
>>> (box * u.mm).units
<Unit('millimeter')>
as_unit(unit)[source]

Declare a unit for unitless geometry:

>>> Box(Point(0, 0, 0), Vector(1, 1, 1)).as_unit('inch').units
<Unit('inch')>
centered(point)[source]

Center this node at the given point:

>>> b = Box(Point(0, 0, 0), Vector(2, 2, 2))
>>> b.centered(Point.origin).envelope()
Box(Point(-1.0, -1.0, -1.0), Vector(2.0, 2.0, 2.0))
envelope()[source]

Returns the axis-aligned bounding box for this shape:

>>> parallelogram = Polygon([
...     Point(0, 0),
...     Point(0, 1),
...     Point(1, 2),
...     Point(1, 1)
... ])
>>> extruded = PolygonExtrusion(
...     PlanarPolygon(Basis.xy, parallelogram),
...     Vector(0, 0, 1)
... )
>>> extruded.envelope()
Box(Point(0, 0, 0), Vector(1, 2, 1))
render(**properties)[source]

Create a pythreejs visualization of this geometry for use in interactive notebooks.

rotate(axis, theta)[source]

Rotate this geometry around the given axis vector by theta radians.

rotate_at(origin, axis, theta)[source]

Rotate this geometry about the given origin and axis by theta radians.

scale(scale)[source]

Scale this geometry by the provided scale vector.

translate(delta)[source]

Translate this geometry by the provided translate vector.

class petrify.solid.PlanarPolygon(basis, polygon)[source]

Bases: object

A two-dimensional Polygon2 or ComplexPolygon2 embedded in three-dimensional space via a Basis:

>>> tri = plane.Polygon2([
...     plane.Point2(0, 0),
...     plane.Point2(0, 2),
...     plane.Point2(1, 1)
... ])
>>> triangle = PlanarPolygon(Basis.xy, tri)
>>> triangle.project()
[Polygon([Point(0, 0, 0), Point(0, 2, 0), Point(1, 1, 0)])]
render()[source]

Visualize this polygon in a Jupyter notebook.

class petrify.solid.Point[source]

Bases: petrify.generic.Vector

A generic constructor that chooses the correct variant of Point2 or Point3 based on argument count:

>>> Point(1, 2)
Point(1, 2)
>>> Point(1, 2, 3)
Point(1, 2, 3)
class petrify.solid.Polygon[source]

Bases: object

A generic constructor that chooses the correct variant of Polygon2 or Polygon3 based on the embedding of the passed arguments:

>>> Polygon([Point(0, 0), Point(1, 0), Point(1, 1)])
Polygon([Point(0, 0), Point(1, 0), Point(1, 1)])
>>> Polygon([Point(0, 0, 0), Point(1, 0, 0), Point(1, 1, 1)])
Polygon([Point(0, 0, 0), Point(1, 0, 0), Point(1, 1, 1)])
>>> Polygon([Point(0, 0), Point(1, 1, 2)])
Traceback (most recent call last):
...
AssertionError: arguments must either be all spatial or all planar
class petrify.solid.PolygonExtrusion(footprint, direction)[source]

Bases: petrify.solid.Extrusion

Extrusion of a PlanarPolygon created from a two-dimensional Polygon or ComplexPolygon2 into three-dimensional space:

>>> triangle = Polygon([
...     Point(0, 0),
...     Point(0, 2),
...     Point(1, 1)
... ])
>>> planar = PlanarPolygon(Basis.xy, triangle)
>>> extruded = PolygonExtrusion(planar, Vector(0, 0, 1))
footprint :
a PlanarPolygon object describing a the polygon that will be extruded in the given direction
direction :
A Vector defining which direction the polygon will be linearly extruded into.
as_unit(unit)

Declare a unit for unitless geometry:

>>> Box(Point(0, 0, 0), Vector(1, 1, 1)).as_unit('inch').units
<Unit('inch')>
centered(point)

Center this node at the given point:

>>> b = Box(Point(0, 0, 0), Vector(2, 2, 2))
>>> b.centered(Point.origin).envelope()
Box(Point(-1.0, -1.0, -1.0), Vector(2.0, 2.0, 2.0))
envelope()

Returns the axis-aligned bounding box for this shape:

>>> parallelogram = Polygon([
...     Point(0, 0),
...     Point(0, 1),
...     Point(1, 2),
...     Point(1, 1)
... ])
>>> extruded = PolygonExtrusion(
...     PlanarPolygon(Basis.xy, parallelogram),
...     Vector(0, 0, 1)
... )
>>> extruded.envelope()
Box(Point(0, 0, 0), Vector(1, 2, 1))
generate_polygons()

Calculates all polygons for this shape.

render(**properties)

Create a pythreejs visualization of this geometry for use in interactive notebooks.

ring(bottom, top)

Builds a ring from two slices.

rotate(axis, theta)

Rotate this geometry around the given axis vector by theta radians.

rotate_at(origin, axis, theta)

Rotate this geometry about the given origin and axis by theta radians.

scale(scale)

Scale this geometry by the provided scale vector.

translate(delta)

Translate this geometry by the provided translate vector.

class petrify.solid.Sphere(center, radius, segments=10)[source]

Bases: petrify.solid.Extrusion

A sphere defined via center and a radius

>>> ball = Sphere(Point.origin, 1)

The actual sphere is approximated by creating many segments of longitudinal circles, each in turn approximated with the same number of segments

center :
a Point defining the center of this sphere
radius :
the radius of the sphere.
segments :
the number of longitudinal circles and segments to use when approximating the sphere.
as_unit(unit)

Declare a unit for unitless geometry:

>>> Box(Point(0, 0, 0), Vector(1, 1, 1)).as_unit('inch').units
<Unit('inch')>
centered(point)

Center this node at the given point:

>>> b = Box(Point(0, 0, 0), Vector(2, 2, 2))
>>> b.centered(Point.origin).envelope()
Box(Point(-1.0, -1.0, -1.0), Vector(2.0, 2.0, 2.0))
envelope()

Returns the axis-aligned bounding box for this shape:

>>> parallelogram = Polygon([
...     Point(0, 0),
...     Point(0, 1),
...     Point(1, 2),
...     Point(1, 1)
... ])
>>> extruded = PolygonExtrusion(
...     PlanarPolygon(Basis.xy, parallelogram),
...     Vector(0, 0, 1)
... )
>>> extruded.envelope()
Box(Point(0, 0, 0), Vector(1, 2, 1))
generate_polygons()

Calculates all polygons for this shape.

render(**properties)

Create a pythreejs visualization of this geometry for use in interactive notebooks.

ring(bottom, top)

Builds a ring from two slices.

rotate(axis, theta)

Rotate this geometry around the given axis vector by theta radians.

rotate_at(origin, axis, theta)

Rotate this geometry about the given origin and axis by theta radians.

scale(scale)

Scale this geometry by the provided scale vector.

translate(delta)

Translate this geometry by the provided translate vector.

class petrify.solid.Spun(axis, start, turns)[source]

Bases: petrify.solid.Node

A three-dimensional object built from two-dimensional profiles rotated uniformly around an axis:

>>> axis = Vector.basis.z
>>> start = Vector.basis.y
>>> tri = Polygon([
...     Point(0, 0),
...     Point(1, 1),
...     Point(0, 2)
... ])
>>> spun = Spun(axis, start, [tri] * 5)

The y-axis of the profile is used as the rotational axis when building the solid.

as_unit(unit)

Declare a unit for unitless geometry:

>>> Box(Point(0, 0, 0), Vector(1, 1, 1)).as_unit('inch').units
<Unit('inch')>
centered(point)

Center this node at the given point:

>>> b = Box(Point(0, 0, 0), Vector(2, 2, 2))
>>> b.centered(Point.origin).envelope()
Box(Point(-1.0, -1.0, -1.0), Vector(2.0, 2.0, 2.0))
envelope()

Returns the axis-aligned bounding box for this shape:

>>> parallelogram = Polygon([
...     Point(0, 0),
...     Point(0, 1),
...     Point(1, 2),
...     Point(1, 1)
... ])
>>> extruded = PolygonExtrusion(
...     PlanarPolygon(Basis.xy, parallelogram),
...     Vector(0, 0, 1)
... )
>>> extruded.envelope()
Box(Point(0, 0, 0), Vector(1, 2, 1))
generate_polygons()[source]

Calculates all polygons for this shape.

render(**properties)

Create a pythreejs visualization of this geometry for use in interactive notebooks.

rotate(axis, theta)

Rotate this geometry around the given axis vector by theta radians.

rotate_at(origin, axis, theta)

Rotate this geometry about the given origin and axis by theta radians.

rotation(a, b)[source]

Builds a ring from two slices.

scale(scale)

Scale this geometry by the provided scale vector.

translate(delta)

Translate this geometry by the provided translate vector.

class petrify.solid.Transformed(prior, matrix)[source]

Bases: petrify.solid.Node

Geometry that has had a matrix transform applied to it.

You probably should use methods on Node instead of instantiating this class directly.

as_unit(unit)

Declare a unit for unitless geometry:

>>> Box(Point(0, 0, 0), Vector(1, 1, 1)).as_unit('inch').units
<Unit('inch')>
centered(point)

Center this node at the given point:

>>> b = Box(Point(0, 0, 0), Vector(2, 2, 2))
>>> b.centered(Point.origin).envelope()
Box(Point(-1.0, -1.0, -1.0), Vector(2.0, 2.0, 2.0))
envelope()

Returns the axis-aligned bounding box for this shape:

>>> parallelogram = Polygon([
...     Point(0, 0),
...     Point(0, 1),
...     Point(1, 2),
...     Point(1, 1)
... ])
>>> extruded = PolygonExtrusion(
...     PlanarPolygon(Basis.xy, parallelogram),
...     Vector(0, 0, 1)
... )
>>> extruded.envelope()
Box(Point(0, 0, 0), Vector(1, 2, 1))
render(**properties)

Create a pythreejs visualization of this geometry for use in interactive notebooks.

rotate(axis, theta)

Rotate this geometry around the given axis vector by theta radians.

rotate_at(origin, axis, theta)

Rotate this geometry about the given origin and axis by theta radians.

scale(scale)

Scale this geometry by the provided scale vector.

translate(delta)

Translate this geometry by the provided translate vector.

class petrify.solid.Union(parts)[source]

Bases: petrify.solid.Node

Defines a union of a list of parts:

>>> many = Union([
...     Box(Point(0, 0, 0), Vector(10, 1, 1)),
...     Box(Point(0, 0, 0), Vector(1, 10, 1)),
...     Box(Point(0, 0, 0), Vector(1, 1, 10)),
... ])
as_unit(unit)

Declare a unit for unitless geometry:

>>> Box(Point(0, 0, 0), Vector(1, 1, 1)).as_unit('inch').units
<Unit('inch')>
centered(point)

Center this node at the given point:

>>> b = Box(Point(0, 0, 0), Vector(2, 2, 2))
>>> b.centered(Point.origin).envelope()
Box(Point(-1.0, -1.0, -1.0), Vector(2.0, 2.0, 2.0))
envelope()

Returns the axis-aligned bounding box for this shape:

>>> parallelogram = Polygon([
...     Point(0, 0),
...     Point(0, 1),
...     Point(1, 2),
...     Point(1, 1)
... ])
>>> extruded = PolygonExtrusion(
...     PlanarPolygon(Basis.xy, parallelogram),
...     Vector(0, 0, 1)
... )
>>> extruded.envelope()
Box(Point(0, 0, 0), Vector(1, 2, 1))
render(**properties)

Create a pythreejs visualization of this geometry for use in interactive notebooks.

rotate(axis, theta)

Rotate this geometry around the given axis vector by theta radians.

rotate_at(origin, axis, theta)

Rotate this geometry about the given origin and axis by theta radians.

scale(scale)

Scale this geometry by the provided scale vector.

translate(delta)

Translate this geometry by the provided translate vector.

class petrify.solid.Vector[source]

Bases: object

A generic constructor that chooses the correct variant of Vector or Vector based on argument count:

>>> Vector(1, 2)
Vector(1, 2)
>>> Vector(1, 2, 3)
Vector(1, 2, 3)
class petrify.solid.Vector3(x=0, y=0, z=0)[source]

Bases: petrify.generic.Concrete, petrify.generic.Vector, petrify.space.util.Spatial

A three-dimensional vector supporting all corresponding built-in math operators:

>>> Vector(1, 2, 3) + Vector(2, 2, 2)
Vector(3, 4, 5)
>>> Vector(1, 2, 3) - Vector(2, 2, 2)
Vector(-1, 0, 1)
>>> Vector(1, 0, 1) * 5
Vector(5, 0, 5)
>>> Vector(1, 0, 1) / 5
Vector(0.2, 0.0, 0.2)
>>> Vector(1, 1, 1) == Vector(1, 1, 1)
True

In addition to many other specialized vector operations.

Defines convenience .basis members for commonly used basis vectors:

>>> Vector.basis.x; Vector.bx
Vector(1, 0, 0)
Vector(1, 0, 0)
>>> Vector.basis.y; Vector.by
Vector(0, 1, 0)
Vector(0, 1, 0)
>>> Vector.basis.z; Vector.bz
Vector(0, 0, 1)
Vector(0, 0, 1)
angle(other)[source]

Return the angle to the vector other.

cross(other)[source]

The cross product of this vector and the other.

dot(other)[source]

The dot product of this vector and the other.

normalized()[source]

Returns a vector with the same direction but unit (1) length:

>>> Vector(0, 0, 5).normalized()
Vector(0.0, 0.0, 1.0)
point()[source]

Convert this vector into a point.

project(other)[source]

Return one vector projected on the vector other.

reflect(normal)[source]

Reflect this vector across a plane with the given normal

Note

Assumes the given normal has unit (1) length.

rotate(axis, theta)[source]

Return a new vector rotated around axis by angle theta. Right hand rule applies.

rounded(place=None)[source]

Rounds all elements to place decimals.

snap(grid)[source]

Snaps this vector to a grid:

>>> Vector(1.15, 1.15, 0.9).snap(0.25)
Vector(1.25, 1.25, 1.0)
class petrify.solid.View(node, **data)[source]

Bases: petrify.solid.Node

Apply view properties to geometry.

>>> v = View(Box(Point.origin, Vector(1, 1, 1)), wireframe=True)
as_unit(unit)

Declare a unit for unitless geometry:

>>> Box(Point(0, 0, 0), Vector(1, 1, 1)).as_unit('inch').units
<Unit('inch')>
centered(point)

Center this node at the given point:

>>> b = Box(Point(0, 0, 0), Vector(2, 2, 2))
>>> b.centered(Point.origin).envelope()
Box(Point(-1.0, -1.0, -1.0), Vector(2.0, 2.0, 2.0))
envelope()

Returns the axis-aligned bounding box for this shape:

>>> parallelogram = Polygon([
...     Point(0, 0),
...     Point(0, 1),
...     Point(1, 2),
...     Point(1, 1)
... ])
>>> extruded = PolygonExtrusion(
...     PlanarPolygon(Basis.xy, parallelogram),
...     Vector(0, 0, 1)
... )
>>> extruded.envelope()
Box(Point(0, 0, 0), Vector(1, 2, 1))
render(**properties)

Create a pythreejs visualization of this geometry for use in interactive notebooks.

rotate(axis, theta)[source]

Rotate this geometry around the given axis vector by theta radians.

rotate_at(origin, axis, theta)[source]

Rotate this geometry about the given origin and axis by theta radians.

scale(scale)[source]

Scale this geometry by the provided scale vector.

translate(delta)[source]

Translate this geometry by the provided translate vector.

petrify.solid.perpendicular(axis)[source]

Return a vector that is perpendicular to the given axis.

petrify.solid.valid_scalar(v)[source]

Checks if v is a valid scalar value for the purposes of this library:

>>> valid_scalar(1)
True
>>> valid_scalar(1.0)
True
>>> valid_scalar('abc')
False