Geometries

Basic shapes

from pathlib import Path

import cadquery as cq
import numpy as np

from microgen.shape import newGeometry

shapes = {
    "box": {"dim": (0.8, 0.8, 0.8)},
    "sphere": {"radius": 0.5},
    "capsule": {"height": 0.5, "radius": 0.3},
    "cylinder": {"height": 0.5, "radius": 0.5},
    "ellipsoid": {"radii": (0.5, 0.25, 0.3)},
    "extrudedpolygon": {
        "listCorners": [
            (0.5, 0),
            (0.25, 0.44),
            (-0.25, 0.44),
            (-0.5, 0),
            (-0.25, -0.44),
            (0.25, -0.44),
            (0.5, 0),
        ],
        "height": 0.5,
    },
}


assembly = cq.Assembly()

n_col = 3
n_row = np.ceil(len(shapes) / n_col)
i = 0
for shape, param_geom in shapes.items():
    i_x = i % n_col
    i_y = i // n_col
    elem = newGeometry(
        shape=shape,
        center=(1.2 * (i_x - 0.5 * (n_col - 1)), -1.2 * (i_y - 0.5 * (n_row - 1)), 0),
        orientation=(90, 90, 90),
        param_geom=param_geom,
    )
    assembly.add(elem.generate())
    i = i + 1

compound = assembly.toCompound()
stl_file = str(Path(__file__).parent / "shapes.stl")
cq.exporters.export(compound, stl_file)
../_images/shapes.png

Platon polyhedra

from pathlib import Path

import cadquery as cq

import microgen

filenames = [
    "tetrahedron.obj",
    "cube.obj",
    "octahedron.obj",
    "dodecahedron.obj",
    "icosahedron.obj",
]
filenames = [str(Path(__file__).parent / file) for file in filenames]
platon_solids = []

i = 0
for filename in filenames:
    dic = microgen.shape.polyhedron.read_obj(filename)
    solid = microgen.shape.polyhedron.Polyhedron(dic=dic)
    shape = solid.generate()
    shape = shape.translate(cq.Vector(-6 + 3 * i, 0, 0))
    platon_solids.append(shape)
    i += 1

stl_file = str(Path(__file__).parent / "platon.stl")
cq.exporters.export(cq.Compound.makeCompound(platon_solids), stl_file)
../_images/platon.png