Exemple #1
0
 def test_pipe_shell(self):
     proto0 = zencad.circle(20, wire=True)
     proto1 = zencad.circle(30, wire=True).up(10)
     proto2 = zencad.circle(30, wire=True).up(20)
     path = zencad.interpolate([(0, 0, 0), (0, 0, 10), (0, 10, 20)])
     zencad.pipe_shell([proto0, proto1, proto2], path)
     zencad.pipe_shell(profiles=[proto0, proto1, proto2], spine=path)
Exemple #2
0
 def test_loft(self):
     arr = [
         zencad.circle(20, wire=True),
         zencad.circle(20, wire=True).up(10),
         zencad.square(20, wire=True, center=True).up(20),
     ]
     zencad.loft(arr)
     zencad.loft(arr, True)
     zencad.loft(arr=arr, smooth=True)
Exemple #3
0
 def test_normales(self):
     self.assertGreater(zencad.circle(r=10).normal().z, 0)
     self.assertGreater(zencad.ellipse(r1=10, r2=5).normal().z, 0)
     self.assertGreater(zencad.ngon(r=10, n=3).normal().z, 0)
     self.assertGreater(zencad.ngon(r=10, n=6).normal().z, 0)
     self.assertGreater(zencad.ngon(r=10, n=12).normal().z, 0)
     self.assertGreater(zencad.ngon(r=10, n=28).normal().z, 0)
     self.assertGreater(zencad.rectangle(a=10, b=20).normal().z, 0)
     self.assertGreater(
         zencad.rectangle(a=10, b=20, center=True).normal().z, 0)
     self.assertGreater(zencad.square(a=10).normal().z, 0)
     self.assertGreater(zencad.square(a=10, center=True).normal().z, 0)
Exemple #4
0
def svg_to_shape(path):
    reader = SvgReader()
    return reader.read_string(open(path, "r").read())


if __name__ == "__main__":
    import zencad
    import zencad.gutil

    zencad.lazifier.fastdo = True

    shp = \
        (
            zencad.rectangle(10, 20)
            + zencad.rectangle(10, 20, center=True)
            + zencad.ellipse(10, 8)
            - zencad.circle(3)
        )

    zencad.hl(shp.down(2))

    clr = zencad.color.Color(0.5, 0, 0.5)

    mapping = False

    shape_to_svg("test.svg", shp, color=clr, mapping=mapping)

    m = svg_to_shape("test.svg")
    zencad.disp(m)
    zencad.show()
Exemple #5
0
 def test_fill(self):
     zencad.fill(zencad.circle(5, wire=True)).unlazy()
     zencad.circle(5, wire=True).fill().unlazy()
Exemple #6
0
 def test_circle_probe(self):
     radius = 30
     angle = zencad.deg(45)
     start = zencad.deg(45)
     stop = zencad.deg(60)
     zencad.circle(r=radius, wire=True)
     zencad.circle(r=radius, angle=angle, wire=True)
     zencad.circle(r=radius, angle=(start, stop), wire=True)
     zencad.circle(r=radius, wire=False)
     zencad.circle(r=radius, angle=angle, wire=False)
     zencad.circle(r=radius, angle=(start, stop), wire=False)
Exemple #7
0
 def test_pipe(self):
     proto = zencad.circle(20)
     path = zencad.interpolate([(0, 0, 0), (0, 0, 10), (0, 10, 20)])
     zencad.pipe(proto, path)
     zencad.pipe(profile=proto, spine=path)
Exemple #8
0
def build():
    r = io.imread("image.png", as_gray=True)

    # Find contours at a constant value of 0.8
    contours = measure.find_contours(r, 0.8)

    zcountours = [
        zencad.interpolate([zencad.point3(t[0], t[1]) for t in contour])
        for contour in contours
    ]

    gons = [z.fill() for z in zcountours if z.is_closed()]
    ncls = [z for z in zcountours if not z.is_closed()]

    ints = []
    for i in range(0, len(gons)):
        for j in range(0, len(gons)):
            if i == j:
                continue
            ints.append(gons[i] ^ gons[j])

    ints = zencad.union(ints)
    gons = [g - ints for g in gons]

    gons = zencad.union(gons)

    pnts = chain(*[n.endpoints().unlazy() for n in ncls])
    pnts = list(pnts)

    rpnts = []
    for i in range(0, len(pnts)):
        for j in range(0, len(pnts)):
            if i == j or j > i:
                continue
            if (
                math.sqrt(
                    (pnts[i].x - pnts[j].x) ** 2
                    + (pnts[i].y - pnts[j].y) ** 2
                    + (pnts[i].z - pnts[j].z) ** 2
                )
                < 150
            ):
                rpnts.append((i, j))

    wires = ncls + [zencad.segment(pnts[a], pnts[b]) for a, b in rpnts]

    wires = [
        wires[0],
        wires[4],
        wires[1],
        wires[7],
        wires[3],
        wires[6],
        wires[2],
        wires[5],
    ]

    gons = gons.left(760 / 2).back(768 / 2)
    w0 = zencad.sew(wires).left(760 / 2).back(768 / 2)
    w1 = w0.scale(1.2, zencad.point3(0, 0, 0))

    f = w1.fill() - w0.fill()

    mechanicus = gons + f
    mechanicus = mechanicus.extrude(20).up(20)

    base = zencad.circle(r=500).extrude(20)

    return mechanicus, base, zcountours
Exemple #9
0
 def test_sweep(self):
     proto = zencad.circle(20, wire=True)
     path = zencad.interpolate([(0, 0, 0), (0, 0, 10), (0, 10, 20)])
     zencad.sweep(proto, path)
     zencad.sweep(proto=proto, path=path)
Exemple #10
0
 def test_pipe_shell(self):
     proto = zencad.circle(20, wire=True)
     path = zencad.interpolate([(0, 0, 0), (0, 0, 10), (0, 10, 20)])
     zencad.pipe_shell(proto, path)
     zencad.pipe_shell(proto=proto, path=path)