51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
from typing import List
|
|
|
|
import solid as scad
|
|
|
|
from .globals import SEGMENTS
|
|
|
|
import numpy as np
|
|
import logging as log
|
|
|
|
log.basicConfig(level=log.INFO)
|
|
|
|
def round_box(x_dim: float, y_dim: float, z_dim: float, radius: float, segments: int = 32):
|
|
"""creates a round box with radius r
|
|
|
|
.. image:: img/round_box.png
|
|
"""
|
|
box = scad.cube([x_dim - 2 * radius, y_dim - 2 * radius, z_dim - 2 * radius])
|
|
wall = scad.sphere(r=radius, segments=segments)
|
|
|
|
return scad.translate([radius, radius, radius])(
|
|
scad.minkowski()(box, wall)
|
|
)
|
|
|
|
|
|
def round_flat_box(x: float, y: float, z: float, r: float, segments: int = 32):
|
|
"""creates a round box with radius r and flat top/bottom
|
|
|
|
.. image:: img/round_flat_box.png
|
|
"""
|
|
box = scad.cube([x - 2 * r, y - 2 * r, z- 2 * r])
|
|
wall = scad.cylinder(r=r, h=2*r, segments=SEGMENTS)
|
|
|
|
return scad.translate([r, r, 0])(
|
|
scad.minkowski()(box, wall)
|
|
)
|
|
|
|
|
|
def pill(ps: List[List[float]], r, segments: int = 36):
|
|
if len(ps) < 2:
|
|
raise Exception("requires 2 or more points")
|
|
s = scad.sphere(r=r, segments=segments)
|
|
|
|
spheres = []
|
|
# log.info(ps)
|
|
for p in ps:
|
|
spheres.append(
|
|
scad.translate(p)(s)
|
|
)
|
|
|
|
return scad.hull()(*spheres)
|