def CreateSpiral(self, fp, a): m = fp.Profile.Shape.BoundBox.Center # Center of the profile myNumRot = fp.Rotations myRadius = m.distanceToLine(fp.Center, fp.Center + fp.Axis) myGrowth = Growth myPitch = 1.0 myHeight = myNumRot * myPitch myAngle = atan(myGrowth / myPitch) assert myGrowth > 0, u"Growth too small" assert myNumRot > 0, u"Number of rotations too small" aPnt = VEC(0.0, 0.0, 0.0) aDir = VEC(2.0 * pi, myPitch, 0.0) surf = Part.Cone(aPnt, DIR_Z, 1.0, 0.0) line = Part.LineSegment(aPnt, aDir) beg = line.value(0) end = line.value(aDir.Length * myNumRot) # calculate end point for conical helix v = myHeight / cos(myAngle) u = myNumRot * 2.0 * pi segm = Part.LineSegment(beg, VEC(u, v, 0)) edgeOnSurf = surf.project(segm) wire = edgeOnSurf.toShape() aPlane = Part.Plane(aPnt, DIR_Z) range = (myNumRot + 1) * myGrowth + 1 + myRadius aPlane.toShape().project(wire) return spiral
def __init__(self): super(Revolution, self).__init__('Revolution') x = 3.198144353947543 z = 6.783942267687237 c = CENTER a = 244.75946975372221 b = 424.7594697537222 c1 = makeCircle(7.5, c, DIR_Y, a, b) c2 = makeCircle(7.5, c, VEC(-0.904526, 0, -0.426419), a, b) c1.vertices = c2.vertices = [Vertex(VEC(x,0,-z)), Vertex(VEC(-x,0,z))] c3 = makeLine(VEC(-x, 0, z), VEC( x, 0,-z)) self.Shape._edges = [c1, c2, c3]
def __init__(self, part, radA, radB): if (isinstance(radA, VEC)): a = part b = radA c = radB C = b - a B = c - a B2 = (a.x**2+a.y**2+a.z**2)-(c.x**2+c.y**2+c.z**2) C2 = (a.x**2+a.y**2+a.z**2)-(b.x**2+B.y**2+b.z**2) CB = C.cross(B) # axis D = (B.y-C.y*B.x/C.x) ZZ1 = -(B.z-C.z*B.x/C.x)/ D Z01 = -(B2-B.x/C.x*C2)/(2*D) ZZ2 = -(ZZ1*C.y+C.z)/C.x Z02 = -(2*Z01*C.y+C2)/(2*C.x) dz = -((Z02-a.x)*CB.x - (Z01-a.y)*CB.y - a.z*CB.z)/(ZZ2*CB.x-ZZ1*CB.y+CB.z) dx = ZZ2*dz + Z02 dy = ZZ1*dz + Z01 center = VEC(dx, dy, dz) circle = Circle(center, CB, (center-a).Length) super(ArcOfCircle, self).__init__('ArcOfCircle', circle, circle.parameter(a), circle.parameter(b)) else: if (radA == radB): raise OCCError(u"Geom_TrimmedCurve::U1 == U2") super(ArcOfCircle, self).__init__('ArcOfCircle', part, radA, radB)
def Center(self): s = self.Direction e = self.EndPoint x = (e.x + s.x) / 2.0 y = (e.y + s.y) / 2.0 z = (e.z + s.z) / 2.0 return VEC(x, y, z)
def __init__(self): super(Cone, self).__init__(name = 'Cone') self.Radius1 = 1.0 self.Radius2 = 0.0 self.Height = 10 self.Angle = 45 self.Axis = DIR_Z self.Apex = VEC(0.0, 0.0, self.Height)
def __valueAtEllipse__(ra, rb, center, axis, u): x = VEC(cos(u) * ra, sin(u) * rb, 0) theta = axis.getAngle(DIR_Z) if (abs(theta) < 1e-06): n = DIR_X elif (abs(theta - pi) < 1e-06): n = -DIR_X else: n = DIR_Z.cross(axis) if (n.Length == 0): return x n = n.normalize() a = cos(theta/2) b = n.x*sin(theta/2) c = n.y*sin(theta/2) d = n.z*sin(theta/2) aa, bb, cc, dd = a*a, b*b, c*c, d*d bc, ad, ac, ab, bd, cd = b*c, a*d, a*c, a*b, b*d, c*d m = MAT(aa+bb-cc-dd, 2*(bc+ad), 2*(bd-ac), 0, 2*(bc-ad), aa+cc-bb-dd, 2*(cd+ab), 0, 2*(bd+ac), 2*(cd-ab), aa+dd-bb-cc, 0, 0, 0, 0, 1) return center + m.multiply(x)
'App::PropertyFloat': u'', 'App::PropertyQuantity': u'', 'App::PropertyAngle': u'°', 'App::PropertyDistance': u'mm', 'App::PropertyLength': u'mm', 'App::PropertyPercent': u'%', } DIM_CONSTRAINTS = { 'Angle': u'°', 'Distance': u'mm', 'DistanceX': u'mm', 'DistanceY': u'mm', 'Radius': u'mm', } DIR_X = VEC(1.0, 0.0, 0.0) DIR_Y = VEC(0.0, 1.0, 0.0) DIR_Z = VEC(0.0, 0.0, 1.0) def createPartFeature(doctype, name): fp = FreeCAD.ActiveDocument.addObject(doctype, getObjectName(name)) fp.Label = name return fp def getObjectName(name): if (sys.version_info.major < 3): v = re.sub(r'[^\x00-\x7f]', r'_', name) else: v = re.sub(b'[^\x00-\x7f]', b'_', name.encode('utf8')).decode('utf8')
def value(self, u, v): return self.Center + VEC(self.Radius, 0, 0)
def BoundBox(self): return BoundBox(CENTER, VEC(1.0, 1.0, 1.0))
def getBase(self): x = self.m[0, 2] y = self.m[1, 2] return VEC(x, y, 0)
def BoundBox(self): minBB = CENTER maxBB = VEC(1.0, 1.0, 1.0) return BoundBox(minBB, maxBB)
VAL_FORMAT = { VAL_GUESS: '%s', VAL_UINT8: '%02X', VAL_UINT16: '%03X', VAL_UINT32: '%04X', VAL_UINT64: '%05X', VAL_STR8: '\'%s\'', VAL_STR16: '\"%s\"', VAL_DATETIME: '#%s#', VAL_ENUM: '%s', } MIN_0 = 0.0 MIN_PI = -pi MIN_PI2 = -pi / 2 MIN_INF = float('-inf') MAX_2PI = 2 * pi MAX_PI = pi MAX_PI2 = pi / 2 MAX_INF = float('inf') MAX_LEN = 2e+100 CENTER = VEC(0, 0, 0) DIR_X = VEC(1, 0, 0) DIR_Y = VEC(0, 1, 0) DIR_Z = VEC(0, 0, 1) ENCODING_FS = 'utf8'
def getFloat64_3D(data, index): val = FLOAT64_3D(data, index) return VEC(val), int(index + 0x18)
def getFloat64_2D(data, index): val = FLOAT64_2D(data, index) return VEC(val + (0.0, )), int(index + 0x10)
def execute(self, fp): vec = VEC(fp.Point) fp.Shape = Part.Vertex(vec)
def valueAt(self, value): return VEC(value, value, value) def normalAt(self, value): return DIR_X
def getBase(self): x = self.m[0, 3] y = self.m[1, 3] z = self.m[2, 3] return VEC(x, y, z)