def recompute(self): h1, h2, h3, theta, p1, p2 = self.h1, self.h2, self.h3, self.theta, \ self.p1, self.p2 xvect = (p2 - p1).normalized() angle = (p2 - p1).polar()[1] + theta * pi / 180 yvect = Polar(1, angle) new = Sketch.CreatePath() newpaths = [new] new.AppendLine(p1) new.AppendLine(p1 + h1 * yvect) new = Sketch.CreatePath() newpaths.append(new) new.AppendLine(p1 + h3 * yvect) new.AppendLine(p2 + h3 * yvect) new = Sketch.CreatePath() newpaths.append(new) new.AppendLine(p2) new.AppendLine(p2 + h2 * yvect) for new in newpaths: new.Transform(self.trafo) if self.objects: self.objects[0].SetPaths(newpaths) else: lines = Sketch.PolyBezier(tuple(newpaths)) self.set_objects([lines])
def recompute(self): h1, h2, n, p1, p2 = self.h1, self.h2, self.n, self.p1, self.p2 xvect = (p2 - p1).normalized() yvect = Point(xvect.y, -xvect.x) new = Sketch.CreatePath() newpaths = [new] new.AppendLine(p1) new.AppendLine(p2) new.Transform(self.trafo) for i in range(0, n + 1): new = Sketch.CreatePath() newpaths.append(new) p = p1 + (p2 - p1) / float(n) * i new.AppendLine(p - yvect * h1) new.AppendLine(p + yvect * h2) new.Transform(self.trafo) if self.objects: self.objects[0].SetPaths(newpaths) else: lines = Sketch.PolyBezier(tuple(newpaths)) self.set_objects([lines])
def recompute(self): new = Sketch.CreatePath() newpaths = [new] p1, p2, h, n = self.p1, self.p2, self.h, self.n y1 = f1 * h * uy y2 = f2 * h * uy y3 = h * uy x = (p2 - p1) / float(n) new.AppendLine(p1) new.AppendLine(p2) new.AppendLine(p2 + y3) p = p2 new.AppendLine(p + y1) for i in range(n): p = p - x new.AppendLine(p + y1) new.AppendLine(p + y2) new.AppendLine(p + y1) new.AppendLine(p1 + y1) new.AppendLine(p1 + y3) new.AppendLine(p1) new.Transform(self.trafo) if self.objects: self.objects[0].SetPaths(newpaths) else: obj = Sketch.PolyBezier(tuple(newpaths)) self.set_objects([obj])
def recompute(self): back, l1, l2, l3, d1, d2, d3 = self.back, self.l1, self.l2, self.l3, \ self.d1, self.d2, self.d3 new = Sketch.CreatePath() newpaths1 = [new] #draw the arrow head for p in ((0, -d1), (0, -d1 - d2), (-l1, 0), (0, d1 + d2), (0, d1)): new.AppendLine(Point(p)) # the upper part of the arrow bar k = 1.2 new.AppendBezier(Point(l2, d1), Point(l2, d1 - d3 / k), Point(l2, d1 - d3)) new.AppendLine(Point(l2, -d1 - d3)) new.AppendBezier(Point(l2, -d1 - d3 / k), Point(l2, -d1), Point(0, -d1)) # the lower part of the arrow bar new = Sketch.CreatePath() newpaths2 = [new] new.AppendLine(Point(-l3, -d1)) new.AppendLine(Point(-l3, d1)) new.AppendBezier(Point(l2, d1), Point(l2, d1 - d3 / 3.), Point(l2, d1 - d3)) new.AppendLine(Point(l2, -d1 - d3)) new.AppendBezier(Point(l2, -d1 - d3 / 3.), Point(l2, -d1), Point(-l3, -d1)) new.Transform(Scale(1, -1)) new.Transform(Translation(0, -2 * d3)) if back: newpaths2, newpaths1 = newpaths1, newpaths2 for path in newpaths1 + newpaths2: path.Transform(self.trafo) if self.objects: self.objects[0].SetPaths(newpaths1) self.objects[1].SetPaths(newpaths2) else: obj1 = Sketch.PolyBezier(tuple(newpaths1)) obj2 = Sketch.PolyBezier(tuple(newpaths2)) self.set_objects([obj1, obj2])
def recompute(self): paths = [] self.rows.sort() self.cols.sort() y0 = self.rows[0] y1 = self.rows[-1] x0 = self.cols[0] x1 = self.cols[-1] # make an outer rectangle which can be filled path = Sketch.CreatePath() paths.append(path) path.AppendLine((x0, y0)) path.AppendLine((x1, y0)) path.AppendLine((x1, y1)) path.AppendLine((x0, y1)) path.AppendLine((x0, y0)) # the columns ... for x in self.cols[1:-1]: path = Sketch.CreatePath() paths.append(path) path.AppendLine((x, y0)) path.AppendLine((x, y1)) # the rows ... for y in self.rows[1:-1]: path = Sketch.CreatePath() paths.append(path) path.AppendLine((x0, y)) path.AppendLine((x1, y)) for path in paths: path.Transform(self.trafo) if self.objects: self.objects[0].SetPaths(paths) else: obj = Sketch.PolyBezier(tuple(paths)) obj.SetProperties(line_cap=Sketch.const.CapButt) self.set_objects([obj])
def recompute(self): p1, p2, p3, p4 = self.p1, self.p2, self.p3, self.p4 new = Sketch.CreatePath() newpaths = [new] new.AppendLine(p1) new.AppendLine(p2) new.Transform(self.trafo) new = Sketch.CreatePath() newpaths.append(new) new.AppendLine(p3) new.AppendLine(p4) new.Transform(self.trafo) if self.objects: self.objects[0].SetPaths(newpaths) else: lines = Sketch.PolyBezier(tuple(newpaths)) self.set_objects([lines])
def recompute(self): path = Sketch.CreatePath() top = [path] h = self.h dh = 0.55197 * h d = l = width dd = 0.55197 * d / 2. c = d / 2. path.AppendLine((0, l)) path.AppendBezier((0, l + dh), (c - dd, l + h), (c, l + h)) path.AppendBezier((c + dd, h + l), (d, l + dh), (d, l)) path.AppendBezier((d, l - dh), (c + dd, l - h), (c, l - h)) path.AppendBezier((c - dd, l - h), (0, l - dh), (0, l)) path.Transform(self.trafo) path = Sketch.CreatePath() hull = [path] path.AppendLine((d, l)) path.AppendLine((d, 0)) path.AppendBezier((d, -dh), (c + dd, -h), (c, -h)) path.AppendBezier((c - dd, -h), (0, -dh), (0, 0)) path.AppendLine((0, l)) path.AppendBezier((0, l - dh), (c - dd, l - h), (c, l - h)) path.AppendBezier((c + dd, l - h), (d, l - dh), (d, l)) path.Transform(self.trafo) if self.objects: self.objects[0].SetPaths(hull) self.objects[1].SetPaths(top) else: obj_hull = Sketch.PolyBezier(tuple(hull)) obj_hull.SetProperties(line_join=Sketch.const.JoinRound) obj_top = Sketch.PolyBezier(tuple(top)) self.set_objects([obj_hull, obj_top])
def recompute(self): new = Sketch.CreatePath() newpaths = [new] p1, p2 = self.p1, self.p2 new.AppendLine(p1) new.AppendLine(p2) new.Transform(self.trafo) if self.objects: self.objects[0].SetPaths(newpaths) else: obj = Sketch.PolyBezier(tuple(newpaths)) self.set_objects([obj])
def recompute(self): new = Sketch.CreatePath() newpaths = [new] for p in ((0,0), (self.w1,-self.h2), (self.w1,-self.h1), (self.w2,-self.h1), (self.w2,self.h1), (self.w1,self.h1), (self.w1, self.h2), (0,0)): new.AppendLine(p) new.Transform(self.trafo) if self.objects: self.objects[0].SetPaths(newpaths) else: obj = Sketch.PolyBezier(tuple(newpaths)) self.set_objects([obj])
def recompute(self): h1, h2, w1, w2 = self.GetData() new = Sketch.CreatePath() newpaths = [new] for p in ((-w1, 0), (0, -h2 - h1), (0, -h1), (w2, -h1), (w2, -h2 - h1), (w2 + w1, 0), (w2, h2 + h1), (w2, h1), (0, h1), (0, h2 + h1), (-w1, 0)): new.AppendLine(p) new.Transform(self.trafo) if self.objects: self.objects[0].SetPaths(newpaths) else: obj = Sketch.PolyBezier(tuple(newpaths)) self.set_objects([obj])
def recompute(self): w1, w2, p1, p2 = self.w1, self.w2, self.p1, self.p2 xvect = (p2 - p1).normalized() new = Sketch.CreatePath() newpaths = [new] new.AppendLine(p1 - w1 * xvect) new.AppendLine(p2 + w2 * xvect) new.Transform(self.trafo) if self.objects: self.objects[0].SetPaths(newpaths) else: lines = Sketch.PolyBezier(tuple(newpaths)) self.set_objects([lines])
def recompute(self): path = Sketch.CreatePath() newpaths = [path] h = self.h path.AppendLine((5, 5)) path.AppendBezier((7, 5 + h / 2.), (12, 5 + h), (15, 5 + h)) path.AppendBezier((18, 5 + h), (22, 5 + h / 2), (25, 5)) path.Transform(self.trafo) if self.objects: self.objects[1].SetPaths(tuple(newpaths)) else: skull = Sketch.Ellipse(Scale(22)) skull.Transform(Translation(15, 16)) mouth = Sketch.PolyBezier(tuple(newpaths)) r_eye = Sketch.Ellipse(Scale(3)) l_eye = Sketch.Ellipse(Scale(3)) l_eye.Transform(Translation(7, 21)) r_eye.Transform(Translation(22, 21)) self.set_objects([skull, mouth, r_eye, l_eye])
def recompute(self): new = Sketch.CreatePath() newpaths = [new] r1, r2, n = self.r1, self.r2, self.n alpha = 2 * pi / n for i in range(n): beta = i * alpha p = r1 * cos(beta), r1 * sin(beta) new.AppendLine(p) beta = (i + 0.5) * alpha p = r2 * cos(beta), r2 * sin(beta) new.AppendLine(p) new.AppendLine((r1, 0)) new.Transform(self.trafo) if self.objects: self.objects[0].SetPaths(newpaths) else: obj = Sketch.PolyBezier(tuple(newpaths)) self.set_objects([obj])
def recompute(self): r1 = self.r1 r2 = self.r2 theta1 = self.theta1 theta2 = self.theta2 if theta2 < theta1: theta2 = theta2+360 ring2 = Sketch.Ellipse(start_angle=theta1*pi/180, end_angle=theta2*pi/180, arc_type=0).Paths()[0] ring1 = ring2.Duplicate() ring2.Transform(Scale(r2)) ring1.Transform(Scale(r1)) new = Sketch.CreatePath() newpaths = [new] new.AppendLine(Polar(r1, theta1*pi/180.)) for i in range(ring2.len): segment = ring2.Segment(i) new.AppendSegment(*segment) new.AppendLine(Polar(r2, theta2*pi/180.)) new.AppendLine(Polar(r1, theta2*pi/180.)) ring1.Transform(Scale(-1,1)) ring1.Transform(Rotation((180+theta1+theta2)*pi/180.)) for i in range(ring1.len): s = ring1.Segment(i) new.AppendSegment(*s) for path in newpaths: path.Transform(self.trafo) if self.objects: self.objects[0].SetPaths(newpaths) else: obj = Sketch.PolyBezier(tuple(newpaths)) self.set_objects([obj])
def recompute(self): p1 = Polar(self.l1, self.theta1 * pi / 180) p2 = Polar(self.l2, self.theta2 * pi / 180) new = Sketch.CreatePath() newpaths = [new] new.AppendLine(p1) new.AppendLine((0, 0)) new.AppendLine(p2) new.Transform(self.trafo) alpha = p1.polar()[1] beta = p2.polar()[1] if self.objects: self.objects[0].SetPaths(newpaths) self.objects[1].SetAngles(alpha, beta) trafo = self.trafo(Scale(self.r, self.r)) self.objects[1].set_transformation(trafo) else: lines = Sketch.PolyBezier(tuple(newpaths)) circle = Sketch.Ellipse(start_angle=alpha, end_angle=beta) circle.Transform(Scale(self.r, self.r)) self.set_objects([lines, circle])
def recompute(self): l1, l2, d1, d2, d3 = self.l1, self.l2, self.d1, self.d2, self.d3 new = Sketch.CreatePath() newpaths = [new] #draw the arrow head for p in ((0,-d1), (0, -d1-d2), (-l1,0), (0, d1+d2), (0, d1)): new.AppendLine(Point(p)) # the rounded part k = 1.2 new.AppendBezier(Point(l2,d1), Point(l2, d1-d3/k), Point(l2,d1-d3)) new.AppendLine(Point(l2, -d1-d3)) new.AppendBezier(Point(l2,-d1-d3/k), Point(l2,-d1), Point(0,-d1)) for path in newpaths: path.Transform(self.trafo) if self.objects: self.objects[0].SetPaths(newpaths) else: obj = Sketch.PolyBezier(tuple(newpaths)) self.set_objects([obj])