Back to Guide
Polyhedron tutorial¶
-
class
pyny3d.geoms.
Polyhedron
(polygons, make_ccw=True, **kwargs)[source] Represents 3D polygon-based convex polyhedra.
Under the hood,
pyny.Polyhedron
class uses thepyny.Surface
infrastructure to store and operate with the faces (Polygons). Thispyny.Surface
can be found inPolyhedron.aux_surface
.Instances of this class work as iterable object. When indexed, returns the
pyny.Polygons
which conform it.Parameters: - polygons (list of ndarray, list of
pyny.Polygon
) – Polygons to be set as the Polyhedron. These Polygons have to be contiguous and form a closed polyhedron*. - make_ccw (bool) – If True, points will be sorted ccw for each polygon.
Returns: None
Note
* A concave or open polyhedron will not produce any error and the code will probably work fine but it is important to keep in mind that pyny3d was created to work specifically with convex and closed bodies and you will probably get errors later in other parts of the code.
Warning
This object do NOT check the contiguity of the polygons or whether the polyhedron is closed or not, even it is actually a requirement.
- polygons (list of ndarray, list of
Non-trivial methods¶
As always, you can also use the Polyhedron documentation for method-by-method description.
In this section we are going to see only the .by_two_polygons()
method due
to the Polyhedron class is pretty simple and has not barely any own methods.
by_two_polygons¶
Static method. This method creates a closed Polyhedron by connecting two polygons. Both polygons must have the same number of vertices. These two polygons can be considered the top and the bottom and the rest of its faces (lateral ones) will be generated by matching the polygons’ vertices two by two.
It is important to note that the given polygons (arguments) can be in
pyny.Polygon
format or simply in ndarray
.
An example:
import numpy as np
import pyny3d.geoms as pyny
poly1 = pyny.Polygon(np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]]))
poly2 = pyny.Polygon(np.array([[0, 0, 3], [0.5, 0, 3], [0.5, 0.5, 3], [0, 0.5, 3]]))
polyhedron = pyny.Polyhedron.by_two_polygons(poly1, poly2)
polyhedron.plot('b')
Warning
If an error is raised, probably the Polyhedron you are trying to create has non-planar faces.
Next tutorial: Place tutorial