Provide the Polyhedron
class and functions for creating Polyhedron
instances. The Polyhedron
class defines points
and faces
attributes. Here is a way to use them.
from cqmore.polyhedron import uvSphere
from cqmore import Workplane
sphere = (Workplane()
.polyhedron(*uvSphere(radius = 10, widthSegments = 10, heightSegments = 5))
)
Signature | Description |
---|---|
Polyhedron(points,faces) |
Define points and faces attributes. |
Signature | Description |
---|---|
uvSphere(radius,[heightSegments]) |
Create a UV sphere. |
tetrahedron(radius,[detail]) |
Create a tetrahedron. |
hexahedron(radius,[detail]) |
Create a hexahedron. |
octahedron(radius,[detail]) |
Create a octahedron. |
dodecahedron(radius,[detail]) |
Create a dodecahedron. |
icosahedron(radius,[detail]) |
Create a icosahedron. |
star([outerRadius,innerRadius,height,n]) |
Create a star. |
gridSurface(points[,thickness]) |
Create a surface with a coordinate meshgrid. |
superellipsoid(e,n) |
Create a superellipsoid. |
polarZonohedra(n[,theta]) |
(Preview) Create a polar zonohedra. |
hull(points) |
Create a convex hull through the provided points. |
sweep(profiles) |
Create a swept polyhedron. |
Define a polyhedron.
points
: points of vertices.faces
: face indices.
from cqmore.polyhedron import Polyhedron
from cqmore import Workplane
points = (
(5, -5, -5), (-5, 5, -5), (5, 5, 5), (-5, -5, 5)
)
faces = (
(0, 1, 2), (0, 3, 1), (1, 3, 2), (0, 2, 3)
)
tetrahedron = Polyhedron(points, faces)
tetrahedrons = (Workplane()
.rect(15, 15, forConstruction = True)
.vertices()
.polyhedron(*tetrahedron)
)
Create a UV sphere.
radius
: sphere radius.widthSegments = 3
: number of horizontal segments.heightSegments = 2
: number of vertical segments.
from cqmore.polyhedron import uvSphere
from cqmore import Workplane
sphere = (Workplane()
.polyhedron(*uvSphere(radius = 10, widthSegments = 10, heightSegments = 5))
)
Create a tetrahedron.
radius
: radius of the tetrahedron.detail = 0
: setting this to a value greater than 0 adds vertices making it no longer a tetrahedron.
from cqmore.polyhedron import tetrahedron
from cqmore import Workplane
radius = 1
polyhedra = Workplane()
for detail in range(5):
polyhedra.add(
Workplane()
.polyhedron(*tetrahedron(radius, detail))
.translate((2 * radius * detail, 0, 0))
)
Create a hexahedron.
radius
: radius of the hexahedron.detail = 0
: setting this to a value greater than 0 adds vertices making it no longer a hexahedron.
from cqmore.polyhedron import hexahedron
from cqmore import Workplane
radius = 1
polyhedra = Workplane()
for detail in range(5):
polyhedra.add(
Workplane()
.polyhedron(*hexahedron(radius, detail))
.translate((2 * radius * detail, 0, 0))
)
Create a octahedron.
radius
: radius of the octahedron.detail = 0
: setting this to a value greater than 0 adds vertices making it no longer a octahedron.
from cqmore.polyhedron import octahedron
from cqmore import Workplane
radius = 1
polyhedra = Workplane()
for detail in range(5):
polyhedra.add(
Workplane()
.polyhedron(*octahedron(radius, detail))
.translate((2 * radius * detail, 0, 0))
)
Create a dodecahedron.
radius
: radius of the dodecahedron.detail = 0
: setting this to a value greater than 0 adds vertices making it no longer a dodecahedron.
from cqmore.polyhedron import dodecahedron
from cqmore import Workplane
radius = 1
polyhedra = Workplane()
for detail in range(5):
polyhedra.add(
Workplane()
.polyhedron(*dodecahedron(radius, detail))
.translate((2 * radius * detail, 0, 0))
)
Create a icosahedron.
radius
: radius of the icosahedron.detail = 0
: setting this to a value greater than 0 adds vertices making it no longer a icosahedron.
from cqmore.polyhedron import icosahedron
from cqmore import Workplane
radius = 1
polyhedra = Workplane()
for detail in range(5):
polyhedra.add(
Workplane()
.polyhedron(*icosahedron(radius, detail))
.translate((2 * radius * detail, 0, 0))
)
Create a star. Default to a pentagram.
outerRadius = 1
: the outer radius of the star.innerRadius = 0.381966
: the inner radius of the star.height = 0.5
: the star height.n = 5
: the burst number.
from cqmore import Workplane
from cqmore.polyhedron import star
polyhedron = Workplane().polyhedron(*star())
Create a surface with a coordinate meshgrid.
points
: a coordinate meshgrid.thickness = 0
: the amount of being thick (return 2D surface if 0).
from math import sqrt, cos, radians
from cqmore import Workplane
from cqmore.polyhedron import gridSurface
def ripple(x, y):
n = radians(sqrt(x ** 2 + y ** 2))
return (x, y, 30 * (cos(n) + cos(3 * n)))
min_value = -200
max_value = 200
step = 10
thickness = 5
points = [[
ripple(x, y)
for y in range(min_value, max_value, step)
] for x in range(min_value, max_value, step)]
sf = Workplane().polyhedron(*gridSurface(points, thickness))
Create a superellipsoid.
e
: the east-west parameter.n
: the north-south parameter.widthSegments = 3
: number of horizontal segments.heightSegments = 2
: number of vertical segments.
from cqmore import Workplane
from cqmore.polyhedron import superellipsoid
r = Workplane().polyhedron(*superellipsoid(2.5, .25, widthSegments = 24, heightSegments = 12))
Create a polar zonohedra.
n
: n equal rhombs surrounding one vertex. (rotational symmetry).theta = 35.5
: the pitch angle of the edges.
from cqmore.polyhedron import polarZonohedra
from cqmore import Workplane
pz = Workplane().polyhedron(*polarZonohedra(8, 45))
Create a convex hull through the provided points.
points
: a list of 3D points.
from cqmore import Workplane
from cqmore.polyhedron import hull
points = (
(50, 50, 50),
(50, 50, 0),
(-50, 50, 0),
(-50, -50, 0),
(50, -50, 0),
(0, 0, 50),
(0, 0, -50)
)
convex_hull = Workplane().polyhedron(*hull(points))
Create a swept polyhedron.
profiles
: list of profiles.closeIdx
: setting it to a value >= 0 creates faces between the first and last profile. The value decides which index of the last profile is connected to the first index of the first profile.
from cqmore import Workplane
from cqmore.polyhedron import sweep
profiles = [
[(10, 0, 0), (10, 0, 10), (20, 0, 10), (20, 0, 0)],
[(0, 10, 0), (0, 10, 10), (0, 20, 10), (0, 20, 0)],
[(-10, 0, 0), (-10, 0, 10), (-20, 0, 10), (-20, 0, 0)],
[(0, -10, 0), (0, -10, 10), (0, -20, 10), (0, -20, 0)]
]
r = Workplane().polyhedron(*sweep(profiles))
from cqmore import Workplane
from cqmore.polyhedron import sweep
profiles = [
[(10, 0, 0), (10, 0, 10), (20, 0, 10), (20, 0, 0)],
[(0, 10, 0), (0, 10, 10), (0, 20, 10), (0, 20, 0)],
[(-10, 0, 0), (-10, 0, 10), (-20, 0, 10), (-20, 0, 0)],
[(0, -10, 0), (0, -10, 10), (0, -20, 10), (0, -20, 0)]
]
r = Workplane().polyhedron(*sweep(profiles, closeIdx = 0))