def test_short_rotate(self): t = zencad.short_rotate((0, 0, 1), (1, 0, 0)) m = zencad.point3(0, 0, 1) m = t(m) self.assertEqual(m, zencad.point3(1, 0, 0))
def test_api(self): a = zencad.interpolate([(0, 0, 0), (0, 0, 1)], [(0, 0, 1), (0, 0, 1)], closed=False) b = zencad.interpolate([(0, 0, 0), (0, 0, 1)], closed=False) self.assertEqual(a.value(0), zencad.point3(0, 0, 0)) self.assertEqual(a.value(1), zencad.point3(0, 0, 1)) self.assertEqual(a.value(0.5), zencad.point3(0, 0, 0.5))
def test_trans_shape(self): x = 10 y = 20 z = 30 v = 10 box = zencad.box(10, 10, 10, center=True).translate(x, y, z) self.assertEqual((zencad.translate(z, y, x)(box)).center().unlazy(), zencad.point3(40, 40, 40))
def test_rotate(self): x = 10 y = 20 z = 30 v = 10 pnt = zencad.point3(x, y, z) ang = zencad.deg(v) self.assertEqual( zencad.rotateX(ang)(pnt), zencad.point3(x, y * math.cos(ang) - z * math.sin(ang), z * math.cos(ang) + y * math.sin(ang))) self.assertEqual( zencad.rotateY(ang)(pnt), zencad.point3(x * math.cos(ang) + z * math.sin(ang), y, z * math.cos(ang) - x * math.sin(ang))) self.assertEqual( zencad.rotateZ(ang)(pnt), zencad.point3(x * math.cos(ang) - y * math.sin(ang), y * math.cos(ang) + x * math.sin(ang), z))
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
def test_translate(self): x = 10 y = 20 z = 30 v = 10 pnt = zencad.point3(x, y, z) self.assertEqual( zencad.translate(z, y, x)(pnt), zencad.point3(40, 40, 40)) self.assertEqual(zencad.up(v)(pnt), zencad.point3(x, y, z + v)) self.assertEqual(zencad.down(v)(pnt), zencad.point3(x, y, z - v)) self.assertEqual(zencad.left(v)(pnt), zencad.point3(x - v, y, z)) self.assertEqual(zencad.right(v)(pnt), zencad.point3(x + v, y, z)) self.assertEqual(zencad.forw(v)(pnt), zencad.point3(x, y + v, z)) self.assertEqual(zencad.back(v)(pnt), zencad.point3(x, y - v, z)) self.assertEqual(zencad.moveX(v)(pnt), zencad.point3(x + v, y, z)) self.assertEqual(zencad.moveY(v)(pnt), zencad.point3(x, y + v, z)) self.assertEqual(zencad.moveZ(v)(pnt), zencad.point3(x, y, z + v))