def plane_circle_arc(self, r, angle, large, sweep, x, y): centers = zencad.gutil.restore_circle_centers(self.current, point3(x, y), r) target = point3(x, y) cent = None if centers[0].early(centers[1]): cent = centers[0] if sweep: self.arc(cent, r, deg(180)) else: self.arc(cent, r, -deg(180)) else: for c in centers: cv = self.current - c tv = target - c angle = cv.angle(tv) if cv.cross(tv).z < 0: angle = -angle if large: if angle <= 0: angle += math.pi * 2 else: angle -= math.pi * 2 if angle >= 0 and sweep is True: self.arc(c, r, angle) if angle < 0 and sweep is False: self.arc(c, r, angle)
def _revol2(profile, r, n=30, yaw=(0, deg(360)), roll=(0, 0), sects=False, nparts=None): rets = [] arrs = [] is_full_circle = abs((yaw[1]-yaw[0]) - deg(360)) < 0.000001 if is_full_circle: endpoint = False if nparts is None: nparts = 2 else: endpoint = True if nparts is None: nparts = 1 def part_of_interval(part, total, a, b): def koeff(idx, tot): return idx / tot def point(a, b, k): return a*(1-k) + b*k return(point(a, b, koeff(part, total)), point(a, b, koeff(part+1, total))) for ipart in range(nparts): part_n = n // nparts part_yaw = part_of_interval(ipart, nparts, yaw[0], yaw[1]) part_roll = part_of_interval(ipart, nparts, roll[0], roll[1]) for w in profile.wires(): m = zencad.geom.exttrans.rotate_array2( r=r, n=part_n, yaw=part_yaw, roll=part_roll, endpoint=endpoint, array=True)(w) arrs.append(m) # Радиус окружности не имеет значения. rets.append( _pipe_shell( m, spine=face._circle(r=100, angle=part_yaw, wire=True), # force_approx_c1=True, frenet=True)) if sects: return arrs return zencad.geom.boolops._union(rets)
def rotate_array2(n, r=None, yaw=(0, deg(360)), roll=(0, 0), endpoint=False, array=DEF_MTRANS_ARRAY, unit=DEF_MTRANS_UNIT): lspace1 = np.linspace(yaw[0], yaw[1], num=n, endpoint=endpoint) lspace2 = np.linspace(roll[0], roll[1], num=n, endpoint=endpoint) transes = [ rotateZ(a) * right(r) * rotateX(deg(90)) * rotateZ(a2) for a, a2 in zip(lspace1, lspace2) ] return multitrans(transes, array=array, unit=unit)
def _ellipse(r1, r2, angle=None, wire=False): if r2 > r1: inversed_sizes = True r1, r2 = r2, r1 else: inversed_sizes = False crv = curve._ellipse(r1, r2) if angle: angle = zencad.util.angle_pair(angle) edg = wire_module._make_edge(crv, angle) if not wire: ret = edg else: ucrv = crv p1 = ucrv._d0(angle[0]) p2 = ucrv._d0(angle[1]) wr = _sew([ edg, wire_module._segment(p1, (0, 0)), wire_module._segment(p2, (0, 0)) ]) ret = _fill(wr) else: edg = wire_module._make_edge(crv) ret = edg if wire else _fill(edg) if inversed_sizes: return rotateZ(deg(90))(ret) else: return ret
def rotate_array(n, yaw=deg(360), endpoint=False, array=DEF_MTRANS_ARRAY, unit=DEF_MTRANS_UNIT): lspace = np.linspace(0, yaw, num=n, endpoint=endpoint) transes = [rotateZ(a) for a in lspace] return multitrans(transes, array=array, unit=unit)
def sphere(r, yaw=None, pitch=None, shell=False): if yaw is not None: if yaw > deg(360): raise Exception("Wrong parametr `yaw`. yaw defined in [0, 2*pi]") if pitch is not None: pitch = angle_pair(pitch) if pitch[0] > pitch[1]: raise Exception( "Wrong parametr `pitch`. pitch[0] should be less then pitch[1]" ) if pitch[0] > pitch[1]: raise Exception( "Wrong parametr `pitch`. pitch[0] should be less then pitch[1]" ) if ( pitch[0] > deg(90) or pitch[1] > deg(90) or pitch[0] < -deg(90) or pitch[1] < -deg(90) ): raise Exception( "Wrong parametr `pitch`. pitch[0] and pitch[1] defined in [-pi/2, pi/2]" ) if yaw is not None: if pitch is not None: m = pyservoce.sphere(r=r, pitch0=pitch[0], pitch1=pitch[1], yaw=yaw) else: m = pyservoce.sphere(r=r, yaw=yaw) else: if pitch is not None: m = pyservoce.sphere(r=r, pitch0=pitch[0], pitch1=pitch[1]) else: m = pyservoce.sphere(r=r) if shell: return m.shells()[0] else: return m
def _revol(shp, r=None, yaw=0.0): if r is not None: shp = shp.rotX(deg(90)).movX(r) ax = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)) if yaw == 0: return Shape(BRepPrimAPI_MakeRevol(shp.Shape(), ax).Shape()) else: return Shape(BRepPrimAPI_MakeRevol(shp.Shape(), ax, yaw).Shape())
def torus(r1, r2, yaw=None, pitch=None, shell=False): if pitch is not None: pitch = angle_pair(pitch) if yaw is not None: m = pyservoce.torus( r1=r1, r2=r2, pitch0=pitch[0], pitch1=pitch[1], yaw=yaw ) else: m = pyservoce.torus(r1=r1, r2=r2, pitch0=pitch[0], pitch1=pitch[1]) else: if yaw is not None: m = pyservoce.torus(r1=r1, r2=r2, yaw=yaw) else: #return pyservoce.torus(r1=r1, r2=r2) m = (pyservoce.torus(r1=r1, r2=r2, yaw=deg(180)) + pyservoce.torus(r1=r1, r2=r2, yaw=deg(180)).rotateZ(deg(180))) if shell: return m.shells()[0] else: return m
def torus(r1, r2, yaw=None, pitch=None): if pitch is not None: pitch = angle_pair(pitch) if yaw is not None: return pyservoce.torus(r1=r1, r2=r2, pitch0=pitch[0], pitch1=pitch[1], yaw=yaw) else: return pyservoce.torus(r1=r1, r2=r2, pitch0=pitch[0], pitch1=pitch[1]) else: if yaw is not None: return pyservoce.torus(r1=r1, r2=r2, yaw=yaw) else: #return pyservoce.torus(r1=r1, r2=r2) return ( pyservoce.torus(r1=r1, r2=r2, yaw=deg(180)) + pyservoce.torus(r1=r1, r2=r2, yaw=deg(180)).rotateZ(deg(180)))
def sphere(r, yaw=None, pitch=None): if yaw is not None: if yaw > deg(360): raise Exception("Wrong parametr `yaw`. yaw defined in [0, 2*pi]") if pitch is not None: if not hasattr(pitch, "__getitem__"): raise Exception("Wrong parametr `pitch`. Must be tuple.") if pitch[0] > pitch[1]: raise Exception( "Wrong parametr `pitch`. pitch[0] should be less then pitch[1]" ) if pitch[0] > pitch[1]: raise Exception( "Wrong parametr `pitch`. pitch[0] should be less then pitch[1]" ) if (pitch[0] > deg(90) or pitch[1] > deg(90) or pitch[0] < -deg(90) or pitch[1] < -deg(90)): raise Exception( "Wrong parametr `pitch`. pitch[0] and pitch[1] defined in [-pi/2, pi/2]" ) if yaw is not None: if pitch is not None: return pyservoce.sphere(r, pitch[0], pitch[1], yaw) else: return pyservoce.sphere(r, yaw) else: if pitch is not None: return pyservoce.sphere(r, pitch[0], pitch[1]) else: return pyservoce.sphere(r)
def rotate_array(n): transes = [ rotateZ(angle) for angle in np.linspace(0, deg(360), num=n, endpoint=False) ] return multitrans(transes)
def revol2(profile, r, n=30, yaw=(0, deg(360)), roll=(0, 0), sects=False, nparts=None): rets = [] arrs = [] is_full_circle = abs((yaw[1] - yaw[0]) - deg(360)) < 0.000001 if is_full_circle: endpoint = False if nparts == None: nparts = 2 else: endpoint = True if nparts == None: nparts = 1 yaw_dist = yaw[1] - yaw[0] roll_dist = roll[1] - roll[0] yaw_step = yaw_dist / nparts roll_step = roll_dist / nparts def part_of_interval(part, total, a, b): total_p = total + 1 koeff = lambda idx, tot: idx / tot point = lambda a, b, k: a * (1 - k) + b * k return (point(a, b, koeff(part, total)), point(a, b, koeff(part + 1, total))) for ipart in range(nparts): part_n = n // nparts part_yaw = part_of_interval(ipart, nparts, yaw[0], yaw[1]) part_roll = part_of_interval(ipart, nparts, roll[0], roll[1]) for w in profile.wires(): m = zencad.geom.transform.rotate_array2(r=r, n=part_n, yaw=part_yaw, roll=part_roll, endpoint=endpoint, array=True)(w) arrs.append(m) # Радиус окружности не имеет значения. rets.append( pyservoce.pipe_shell( profiles=m, spine=zencad.geom.prim2d.circle(r=100, angle=part_yaw, wire=True).unlazy(), #force_approx_c1=True, frenet=True)) if sects: return arrs return zencad.geom.boolean.union(rets)
def revol(profile, r=None, yaw=0.0): if r is not None: profile = profile.rotX(deg(90)).movX(r) return pyservoce.revol(profile, yaw)