Solids

Solids are basic geometric elements used for constructive solid geometry trees.

class pcsg.solid.Solid

Informational base class of Solid objects. This empty class is implemented for type matching purposes.

Sphere

../_images/b7c0fd203877.png

Sphere created with diameter = 1

../_images/8f3344ee7f4e.png

Sphere created with radius = 1

Example: Sphere created with diameter = 1

../_images/349bdabfc22e.png
from pcsg import solid

item = solid.Sphere (diameter = 1)

Example: Sphere created with radius = 1

../_images/02296cdde8fc.png
from pcsg import solid

item = solid.Sphere (radius = 1)
class pcsg.solid.Sphere(radius: Optional[float] = None, diameter: Optional[float] = None, name: Optional[str] = None, attributes: Optional[pcsg.attributes.Attributes] = None)

Bases: pcsg.tree.Item, pcsg.solid.Solid

A Sphere is a basic Solid class.

The Sphere can be definied with the parameter radius or diameter. Only the radius will be stored. The Spheres center is at coordinate (0, 0, 0).

radius

Radius of the sphere.

Cube

../_images/1bacf81547f9.png

Cube created with size = (1, 2, 3)

../_images/3c2aef3e4ed6.png

Cube created with size = 2

Example: Cube created with size = (1, 2, 3)

../_images/0975bfca71b1.png
from pcsg import solid

item = solid.Cube (size = (1, 2, 3))

Example: Cube created with size = 2

../_images/077bfe1efd21.png
from pcsg import solid

item = solid.Cube (size = 2)
class pcsg.solid.Cube(size: tuple = (1, 1, 1), name: Optional[str] = None, attributes: Optional[pcsg.attributes.Attributes] = None)

Bases: pcsg.tree.Item, pcsg.solid.Solid

A Cube is a basic Solid class.

The Cube is defined by a three dimensional size tuple. The Cubes center is at coordinate (0, 0, 0).

size

Size of Cube as tuple containing (width: float, height: float, depth: float).

Cylinder

../_images/94c9099bcd56.png

Cylinder created with height = 2 and radius1 = 1

../_images/fdbefdcf08ce.png

Cylinder created with height = 2, radius1 = 1 and radius2 = 0.5

Example: Cylinder created with height = 2 and radius1 = 1

../_images/41c208cb23a6.png
from pcsg import solid

item = solid.Cylinder (
    height = 3,
    radius1 = 1
)

Example: Cylinder created with height = 2, radius1 = 1 and radius2 = 0.5

../_images/f583ae46c2da.png
from pcsg import solid

item = solid.Cylinder (
    height = 3,
    radius1 = 1,
    radius2 = 0.5
)
class pcsg.solid.Cylinder(height: float = 1, radius1: Optional[float] = None, radius2: Optional[float] = None, diameter1: Optional[float] = None, diameter2: Optional[float] = None, name: Optional[str] = None, attributes: Optional[pcsg.attributes.Attributes] = None)

Bases: pcsg.tree.Item, pcsg.solid.Solid

A Cylinder is a basic Solid class.

The Cylinder is defined by a height and two diameters or radius values. The Cylinders center is at coordinate (0, 0, 0).

height

Height of the Cylinder.

radius1

Radius of Cylinder at z = -height / 2.

radius2

Radius of Cylinder at z = height / 2.

Polyhedron

../_images/0d431a0c241d.png

Creating a polyhedron from points and faces

../_images/1ed194fa91a8.png

Importing a ployhedron from an .stl file

../_images/4644cc8963f1.png

Importing a polyhedron from an .off file

../_images/93c2ff559e91.png

Creating a polyhedron by rasterizing a solid

../_images/4856cada8613.png

When a converted solid or imported file has disjunct volumes, a group of polyhedrons will be returned

Example: Creating a polyhedron from points and faces

../_images/d6c4c7a404c9.png
import pcsg

points = (
    (-1, -1, -1),
    (0, 3, -1),
    (1, -1, -1),
    (1, 1, 1)
)

faces = (
    (0, 1, 2),
    (0, 1, 3),
    (1, 2, 3),
    (2, 0, 3)
)

item = pcsg.solid.Polyhedron.fromUnoptimizedMesh (
    points,
    faces
)

Example: Importing a ployhedron from an .stl file

../_images/d42a52fc1b38.png
from pcsg import solid

item = solid.Polyhedron.fromFileSTL ('foo.stl')

Example: Importing a polyhedron from an .off file

../_images/7767fdd31bb2.png
from pcsg import solid

item = solid.Polyhedron.fromFileOFF ('bar.off')

Example: Creating a polyhedron by rasterizing a solid

../_images/50e97a0956ca.png
import pcsg

body = pcsg.solid.LinearExtrude (
    pcsg.transform.Translate (
        pcsg.transform.Scale (
            pcsg.shape.Circle (diameter = 0.5),
            sy = 2
        ),
        x = 1
    ),
    height = 3,
    twist = 720
)

item = pcsg.solid.Polyhedron.fromSolid (body, attributes)

Example: When a converted solid or imported file has disjunct volumes, a group of polyhedrons will be returned

../_images/830bca80bf48.png
import pcsg

body = pcsg.boolean.Difference (
    (
        pcsg.solid.Cube (size = 2),
        pcsg.solid.Sphere (diameter = 2.9)
    )
)

# rasterize body
polyhedrons = pcsg.solid.Polyhedron.fromSolid (body, attributes)

# a group of polyhedrons is expected
assert isinstance (polyhedrons, pcsg.tree.Group)

# colorize polyhedrons inside group
polyhedrons = pcsg.algorithms.distributeColors (polyhedrons)
class pcsg.solid.Polyhedron(points: Optional[tuple] = None, faces: Optional[tuple] = None, normals: Optional[tuple] = None, uvvectors: Optional[tuple] = None, name: Optional[str] = None, attributes: Optional[pcsg.attributes.Attributes] = None)

Bases: pcsg.tree.Item, pcsg.solid.Solid

A Polyhedron is a Solid formed by a closed surface of triangles.

faces

A Polyhedron is definied by a closed set of faces. Each face describes a triangle with optional normals and texture mappings for each point. Faces are references to points, normals and uv vectors in the format (p1, p2, p3[, n1, n2, n3 [, vu1, vu2, vu3]]). A face must have 3, 6 or 9 elements. Normal and vu vector indices are optional and can be set to None if a point doesn’t have a normal or uv mapping.

static fromFileOFF(fileName, name: Optional[str] = None, attributes: Optional[pcsg.attributes.Attributes] = None)

Create a Polyhedron by reading an OFF file. When the imported solid has disjunct volumes, a Group of Polyhedrons will be returned. When the imported solid has no renderable items, Empty will be returned.

static fromFileSTL(fileName, name: Optional[str] = None, attributes: Optional[pcsg.attributes.Attributes] = None)

Create a Polyhedron by reading a STL file. When the imported solid has disjunct volumes, a Group of Polyhedrons will be returned. When the imported solid has no renderable items, Empty will be returned.

static fromSolid(solid: pcsg.tree.Item, rasterizingAttributes: Optional[pcsg.attributes.Attributes] = None, name: Optional[str] = None, attributes: Optional[pcsg.attributes.Attributes] = None)

Create a Polyhedron by rasterizing a three dimensional csg tree Item. The accuracy for rasterizing is calculated from rasterizingAttributes. When the solid has disjunct volumes, a Group of Polyhedrons will be returned. When the solid has no renderable items, Empty will be returned.

static fromUnoptimizedMesh(points, faces, normals=None, uvvectors=None, name: Optional[str] = None, attributes: Optional[pcsg.attributes.Attributes] = None)

Returns a Polygon created from an unoptimized mesh. Duplicated points, normals and uvvectors will be removed and the face indices will be adjusted.

getAdjacentFaceOnEdge(faceId: int, edgeId: int)

Returns the index ot the adjacent face on a faces edge. Each edge is defined by an edgeId: 0 is the edge between point 0 and point 1, 1 is the edge between point 1 and point 2, 2 is the edge beween point 2 and point 0. Per definition, a closed non-self-intersecting Polyhederon has exactly one adjacent face an edge of a face.

This function shall only be called on closed Polyhedrons, otherwise the behaviour will not be defined.

getAdjacentFacesOnCorner(faceId: int, cornerId: int)

Returns a list containg the indices of all adjacent faces connected to a corner of a face. This function will only return true adjacent faces, so faceId will not be included in the result.

This function shall only be called on closed Polyhedrons, otherwise the behaviour will not be defined.

getFacesContainingPoint(pointId: int)

Returns a tuple containing the indices of the all faces attached to a point.

This function shall only be called on closed Polyhedrons, otherwise the behaviour will not be defined.

isClosed()

Returns True when the Polygon has a closed surface, False otherwise.

normals

Tuple containing the three dimensional normal vectors used for defining the normals of a face. Normals are optional.

points

Tuple containing the three dimensional position vectors used for declaraing the corners of a face.

smoothNormals(thresholdAngle: float = 30)

Create a new Polyhedron from this one with auto calculated normal vectors for smooth displaying.

uvvectors

Tuple containing the two dimensional uv vectors used for defining the texture mapping of a face. Uv vectors are optional.

writeFileOFF(file)

Write Polyhedron to .off file.

writeFileSTL(file)

Write Polyhedron to .stl file.

LinearExtrude

../_images/2eeece4d04dd.png
../_images/05d9a5c138b9.png

Linear extrusion of a shape.

../_images/2eeece4d04dd.png
../_images/57ce69467e30.png

Linear extrusion of a shape with twist.

../_images/2eeece4d04dd.png
../_images/961118f73690.png

Linear extrusion of a shape width scale.

Example: Linear extrusion of a shape.

../_images/bdb43b101942.png
../_images/20fbeeb40781.png
import pcsg

outline = pcsg.transform.Translate (
    pcsg.transform.Scale (
        pcsg.shape.Circle (diameter = 1),
        sx = 0.5
    ),
    y = 0.7
)

item = pcsg.solid.LinearExtrude (
    outline,
    height = 3
)

Example: Linear extrusion of a shape with twist.

../_images/bdb43b101942.png
../_images/70b737b19ebe.png
import pcsg

outline = pcsg.transform.Translate (
    pcsg.transform.Scale (
        pcsg.shape.Circle (diameter = 1),
        sx = 0.5
    ),
    y = 0.7
)

item = pcsg.solid.LinearExtrude (
    outline,
    height = 3,
    twist = 450
)

Example: Linear extrusion of a shape width scale.

../_images/bdb43b101942.png
../_images/a0164c6c98e8.png
import pcsg

outline = pcsg.transform.Translate (
    pcsg.transform.Scale (
        pcsg.shape.Circle (diameter = 1),
        sx = 0.5
    ),
    y = 0.7
)

item = pcsg.solid.LinearExtrude (
    outline,
    height = 3,
    scale = 0.5
)
class pcsg.solid.LinearExtrude(children: Optional[object] = None, height: float = 1, twist: float = 0, scale: float = 1.0, name: Optional[str] = None, attributes: Optional[pcsg.attributes.Attributes] = None)

Bases: pcsg.tree.Node, pcsg.solid.Solid

Converts a Shape into a Solid by extruding it along the z axis.

The x/y coordinates are taken from the child geometry, the resulting Solid is centered on the z-axis, i.e. z-coordinates are in range [-height / 2 .. height / 2].

children

Tuple containing a single child. The child must be a two dimensional csg tree Item.

height

Height of the extruded element.

scale

Scale factor applied along the extrusion. Allows extrusions to be cone shaped.

twist

Twist in degrees applied along the extrusion.

RotateExtrude

../_images/ab7433facb52.png
../_images/d265d05d09ab.png

Rotated extrusion of a shape.

Example: Rotated extrusion of a shape.

../_images/d1463bf79320.png
../_images/31a8a22fdf4a.png
import pcsg

outline = pcsg.transform.Translate (
    pcsg.transform.Rotate (
        pcsg.shape.Square (size = 0.7),
        rz = 45
    ),
    x = 1
)

item = pcsg.solid.RotateExtrude (
    outline,
    angle = 90
)
class pcsg.solid.RotateExtrude(children: Optional[object] = None, angle: float = 360, name: Optional[str] = None, attributes: Optional[pcsg.attributes.Attributes] = None)

Bases: pcsg.tree.Node, pcsg.solid.Solid

Extrudes a Shape to a Solid by rotating it around the z-axis.

angle

Angle for extrusion in degrees.

children

Tuple containing a single child. The child must be a two dimensional csg tree Item.