def execute(self, obj): self.Height = float(obj.Height) self.MajorRadius = float(obj.MajorRadius) self.MinorRadius = float(obj.MinorRadius) self.Thickness = float(obj.Thickness) Result = None # base Ellipse vertices and walls after a cut if (self.MajorRadius < self.MinorRadius): self.MajorRadius = self.MinorRadius print("Major Radius must be grater or equal to Minor Radius") Center = App.Vector(App.Vector(0, 0, 0)) W1 = Part.Ellipse(Center, self.MajorRadius, self.MinorRadius) firstFace1 = Part.Face(Part.Wire( W1.toShape())) # one used with secondFace to cut firstFace2 = firstFace1.copy() # Other used to make the bottom W2 = Part.Ellipse(Center, self.MajorRadius - self.Thickness, self.MinorRadius - self.Thickness) secondFace = Part.Face(Part.Wire(W2.toShape())) resultButtom = firstFace1.cut(secondFace) extrude1 = resultButtom.extrude(App.Vector(0, 0, self.Height)) extrude2 = firstFace2.extrude(App.Vector(0, 0, self.Thickness)) fused = extrude1.fuse(extrude2) Result = fused.removeSplitter() obj.Shape = Result
def _generateClippedCurve(self, r1, r2, length, min=0, max=0): if max == 0.0: max = self._length if r1 > r2: major = length - min minor = r1 if min <= 0: theta1 = math.pi / 2 else: theta1 = self._eTheta(major, minor, (r1 / min)) theta2 = math.pi - self._eTheta(major, minor, (r2 / max)) print("tan %f,%f compared to %f,%f" % (theta1, theta2, math.pi / 2, math.pi)) curve = Part.ArcOfEllipse( Part.Ellipse(FreeCAD.Vector(max, 0.0), major, minor), theta1, theta2) for vertex in Part.Wire(curve.toShape()).Vertexes: print(vertex.Point) return curve major = length - min minor = r2 if min <= 0: theta2 = math.pi / 2 else: theta2 = self._eTheta(major, minor, (r2 / min)) theta1 = self._eTheta(major, minor, (r1 / max)) curve = Part.ArcOfEllipse( Part.Ellipse(FreeCAD.Vector(min, 0.0), major, minor), theta1, theta2) return curve
def drawHollow(self): last = self._length - self._thickness outer_curve = Part.ArcOfEllipse( Part.Ellipse(FreeCAD.Vector(0, 0), self._length, self._radius), 0.0, math.pi / 2) inner_curve = Part.ArcOfEllipse( Part.Ellipse(FreeCAD.Vector(0, 0), last, self._radius - self._thickness), 0.0, math.pi / 2) edges = self.hollowLines(last, outer_curve, inner_curve) return edges
def drawCapped(self): last = self._length - self._thickness minor_y = self.innerMinor(last) outer_curve = Part.ArcOfEllipse( Part.Ellipse(FreeCAD.Vector(0, 0), self._length, self._radius), 0.0, math.pi / 2) inner_curve = Part.ArcOfEllipse( Part.Ellipse(FreeCAD.Vector(self._thickness, 0), last - self._thickness, minor_y), 0.0, math.pi / 2) edges = self.cappedLines(last, minor_y, outer_curve, inner_curve) return edges
def testBlockConstraintEllipse(self): self.Doc3 = FreeCAD.newDocument("BlockConstraintTests") ActiveSketch = self.Doc3.addObject('Sketcher::SketchObject', 'Sketch') ActiveSketch.Placement = App.Placement( App.Vector(0.000000, 0.000000, 0.000000), App.Rotation(0.000000, 0.000000, 0.000000, 1.000000)) ActiveSketch.MapMode = "Deactivated" ActiveSketch.addGeometry( Part.Ellipse(App.Vector(-19.129438, 14.345055, 0), App.Vector(-33.806261, 12.085921, 0), App.Vector(-30.689360, 7.107538, 0)), False) ActiveSketch.solve() ActiveSketch.exposeInternalGeometry(0) ActiveSketch.solve() ActiveSketch.movePoint(0, 0, App.Vector(-26.266434, 14.345055, 0), 0) ActiveSketch.solve() ActiveSketch.addConstraint(Sketcher.Constraint( 'Block', 0)) # Block the Ellipse in place ActiveSketch.addConstraint(Sketcher.Constraint( 'Block', 1)) # Block the major axis in place (on purpose) status = ActiveSketch.solve() self.failUnless( status == 0) # no redundants/conflicts/convergence issues ActiveSketch.addConstraint( Sketcher.Constraint('Distance', 1, 27.277350)) # Length of major axis ActiveSketch.setDriving( 6, True ) # ensure length is driving (because pre-existing block constraint on major axis) ActiveSketch.setDatum(6, App.Units.Quantity('28.000000 mm')) status = ActiveSketch.solve() self.failUnless( status == 0) # no redundants/conflicts/convergence issues ActiveSketch.addConstraint( Sketcher.Constraint('Distance', 2, 11.747233)) # Length of minor axis ActiveSketch.setDatum(7, App.Units.Quantity('15.000000 mm')) ActiveSketch.solve() self.failUnless( status == 0) # no redundants/conflicts/convergence issues ActiveSketch.addConstraint(Sketcher.Constraint('Block', 2)) ActiveSketch.solve() self.failUnless( status == 0) # no redundants/conflicts/convergence issues ActiveSketch.addConstraint( Sketcher.Constraint('Horizontal', 1) ) # Make major axis horizontal (together with horizontal and length driving constraints) ActiveSketch.solve() self.failUnless( status == 0) # no redundants/conflicts/convergence issues ActiveSketch.addConstraint( Sketcher.Constraint('DistanceX', 0, 3, -1, 1, 27.655024)) # Locate Ellipse center ActiveSketch.addConstraint( Sketcher.Constraint('DistanceY', 0, 3, -1, 1, -20.877021)) ActiveSketch.setDatum(10, App.Units.Quantity('25.000000 mm')) ActiveSketch.setDatum(11, App.Units.Quantity('-20.000000 mm')) ActiveSketch.solve() self.failUnless( status == 0) # no redundants/conflicts/convergence issues
def test42(self): '''Verify ellipsis results in a proper segmentation of G1 commands.''' ellipse = Part.Edge(Part.Ellipse()) cmds = PathGeom.cmdsForEdge(ellipse) # let's make sure all commands are G1 and there are more than 20 of those self.assertGreater(len(cmds), 20) self.assertTrue(all([cmd.Name == 'G1' for cmd in cmds]))
def make_elliptical_aperture(aperture_height, aperture_width): """Creates a wire outline of a ellipse specified by 2 inputs. aperture_height and aperture_width are the full height and width (the same as if it were a rectangle) Args: aperture_height (float): Total height of the ellipse. aperture_width (float): Total width of the ellipse. Returns: wire1 (FreeCAD wire definition): An outline description of the shape. face1 (FreeCAD face definition): A surface description of the shape. """ # # Define the semi axis b = aperture_height / 2.0 a = aperture_width / 2.0 el1 = Part.Ellipse(Base.Vector(0, 0, 0), a, b) # Make a shape shape1 = el1.toShape() shape1.rotate(Base.Vector(0, 0, 0), Base.Vector(0, 1, 0), 90) # Make a wire outline. wire1 = Part.Wire(shape1.Edges) face1 = Part.Face(wire1) return wire1, face1
def _makeChordProfileRound(self, foreX, chord, thickness, height): # For now, rounded is an ellipse shape ellipse = Part.Ellipse( FreeCAD.Vector(foreX - (chord / 2.0), 0, height), chord / 2.0, thickness / 2.0) wire = Part.Wire([ellipse.toShape()]) return wire
def execute(self, obj): import Part plm = obj.Placement if obj.MajorRadius.Value < obj.MinorRadius.Value: _err = "Error: Major radius is smaller than the minor radius" App.Console.PrintMessage(QT_TRANSLATE_NOOP("Draft", _err)) return if obj.MajorRadius.Value and obj.MinorRadius.Value: ell = Part.Ellipse(App.Vector(0, 0, 0), obj.MajorRadius.Value, obj.MinorRadius.Value) shape = ell.toShape() if hasattr(obj,"FirstAngle"): if obj.FirstAngle.Value != obj.LastAngle.Value: a1 = obj.FirstAngle.getValueAs(App.Units.Radian) a2 = obj.LastAngle.getValueAs(App.Units.Radian) shape = Part.ArcOfEllipse(ell, a1, a2).toShape() shape = Part.Wire(shape) if shape.isClosed(): if hasattr(obj,"MakeFace"): if obj.MakeFace: shape = Part.Face(shape) else: shape = Part.Face(shape) obj.Shape = shape if hasattr(obj, "Area") and hasattr(shape, "Area"): obj.Area = shape.Area obj.Placement = plm obj.positionBySupport()
def drawSolidShoulder(self): outer_curve = Part.ArcOfEllipse( Part.Ellipse(FreeCAD.Vector(0, 0), self._length, self._radius), 0.0, math.pi / 2) edges = self.solidShoulderLines(outer_curve) return edges
def __init__(self,name,origin): self.name = name if not isinstance(origin,Base.Vector): raise RuntimeError("origin is not a Vector") self.origin = origin ox = origin.x oy = origin.y oz = origin.z boardthick = Base.Vector(0,0,self._boardthickness) padthick = Base.Vector(0,0,self._padThick) self.board = Part.makePlane(self._width,self._length,self.origin).extrude(boardthick) headholeX = self._headerX+ox headholeY = self._headerY+oy headholeRadius = self._headerHoleDia/2.0 self.pads = list() for holePadType in self._headholePadTypes: holeorig = Base.Vector(headholeX,headholeY,oz) self.board = \ self.board.cut(Part.Face(Part.Wire(Part.makeCircle(\ headholeRadius,holeorig))).extrude(boardthick)) if holePadType == 'R': padOrigin = holeorig.add(Base.Vector(-self._padsizeX/2,\ -self._padsizeY/2,\ self._boardthickness)) padsurf = Part.makePlane(self._padsizeX,self._padsizeY,padOrigin) elif holePadType == 'O': padOrigin = holeorig.add(Base.Vector(0,0,self._boardthickness)) S1 = padOrigin.add(Base.Vector(0,self._padsizeY/2,0)) S2 = padOrigin.add(Base.Vector(self._padsizeX/2,0,0)) padsurf = Part.Face(Part.Wire(Part.Edge(Part.Ellipse(S1,S2,padOrigin)))) h = Part.Face(Part.Wire(Part.makeCircle(headholeRadius,holeorig.add(Base.Vector(0,0,self._boardthickness))))).extrude(padthick) self.pads.append(padsurf.extrude(padthick).cut(h)) headholeX += 2.54
def _halfEllipse(self, major, minor, thickness, midChord): if major > minor: ellipse = Part.Ellipse( FreeCAD.Vector(midChord, thickness, major), FreeCAD.Vector(midChord - minor, thickness, 0), FreeCAD.Vector(midChord, thickness, 0)) arc = Part.ArcOfEllipse(ellipse, -math.pi / 2, math.pi / 2) else: print("half 1") ellipse = Part.Ellipse( FreeCAD.Vector(midChord - minor, thickness, 0), FreeCAD.Vector(midChord, thickness, major), FreeCAD.Vector(midChord, thickness, 0)) arc = Part.ArcOfEllipse(ellipse, 0, math.pi) line = Part.makeLine((midChord + minor, thickness, 0), (midChord - minor, thickness, 0)) wire = Part.Wire([arc.toShape(), line]) return wire
def makeSpiderLegSegment(baseDiamX=1.0, baseDiamY=0.8, tipDiamX=0.8, tipDiamY=0.6, segLength=5.0, skinThick=0.25, name="segment"): # outer shell is a tapered ellipsoid loft ellipse1 = Part.Ellipse(Base.Vector(0, 0, 0), baseDiamX, baseDiamY) base1 = Part.Wire(Part.Edge(ellipse1)) ellipse2 = Part.Ellipse(Base.Vector(0, 0, 0), tipDiamX, tipDiamY) ellipse2.translate(Base.Vector(0, 0, segLength)) tip1 = Part.Wire(Part.Edge(ellipse2)) shell = App.ActiveDocument.addObject("Part::Feature", "shell") shell.Shape = Part.makeLoft([base1, tip1], True) # hollow core is a tapered ellipsoid loft ellipse3 = Part.Ellipse(Base.Vector(0, 0, 0), baseDiamX - skinThick, baseDiamY - skinThick) base2 = Part.Wire(Part.Edge(ellipse3)) ellipse4 = Part.Ellipse(Base.Vector(0, 0, 0), tipDiamX - skinThick, tipDiamY - skinThick) ellipse4.translate(Base.Vector(0, 0, segLength)) tip2 = Part.Wire(Part.Edge(ellipse4)) core = App.ActiveDocument.addObject("Part::Feature", "core") core.Shape = Part.makeLoft([base2, tip2], True) # Make tube by cutting core from shell legSegment = App.ActiveDocument.addObject("Part::Cut", name) App.ActiveDocument.ActiveObject.Base = shell App.ActiveDocument.ActiveObject.Tool = core # core.Document.removeObject("core") # shell.Document.removeObject("shell") return legSegment
def _generateCurve(self, r1, r2, length, min=0, max=0): if self._clipped: return super()._generateCurve(r1, r2, length, min, max) if self._debugShape: print("r1 = %f, r2 = %f, min = %f, max = %f, length = %f" % (r1, r2, min, max, length)) if max == 0.0: max = length - min if r1 > r2: radius = r1 - r2 curve = Part.ArcOfEllipse( Part.Ellipse(FreeCAD.Vector(max, r2), max - min, radius), math.pi / 2, math.pi) return curve radius = r2 - r1 curve = Part.ArcOfEllipse( Part.Ellipse(FreeCAD.Vector(min, r1), max - min, radius), 0.0, math.pi / 2) return curve
def objEllipse(self, cx, cy, rx, ry, node, mat): """ We distinguish two cases. If it looks like a circle (after transformation), we produce a Circle, else we produce an Ellipse. The difference is clearly visible as we exposeInternalGeometry() of the Ellipse. """ ### CAUTION: Keep in sync with objArc() below. self._matrix_from_svg(mat) c = self._from_svg(cx, cy, bbox=False) ori = self._from_svg(0, 0, bbox=False) vrx = self._from_svg(rx, 0, bbox=False) - ori vry = self._from_svg(0, ry, bbox=False) - ori i = int(self.ske.GeometryCount) if abs(vrx.Length - vry.Length) < epsilon: # it is a circle. self.bbox.add(c + vrx + vry) self.bbox.add(c - vrx - vry) self.ske.addGeometry([ Part.Circle(Center=c, Normal=Base.Vector(0, 0, 1), Radius=vrx.Length) ]) self.stats['objEllipse'] += 1 else: # major axis is defined by Center and S1, # major radius is the distance between Center and S1, # minor radius is the distance between S2 and the major axis. s1 = self._from_svg(cx + rx, cy, bbox=False) s2 = self._from_svg(cx, cy + ry, bbox=False) (V1, V2, V3, V4) = self._ellipse_vertices2d(c, s1, s2) self.bbox.add(V1) self.bbox.add(V2) self.bbox.add(V3) self.bbox.add(V4) self.ske.addGeometry([ Part.Ellipse(S1=V1, S2=V2, Center=c), ]) if self.expose_int: self.ske.exposeInternalGeometry(i) self.stats['objEllipse'] += 1
def execute(self, fp): r1 = fp.a r2 = fp.b s = fp.n z = 0.0 p = 1.0 ####w=2**0.5/2.0 #Ellipse w = 2**0.5 / 2.0 / (1 - s**p) curve = Part.BSplineCurve() curve.setPeriodic() curve.increaseDegree(2) #quadratic curve.insertKnots([i * 1.0 / (4) for i in (1, 2, 3)], [2] * (3)) #5Knots 8 Poles curve.setPole(1, FreeCAD.Vector(0, -r2, z), 1) curve.setPole(2, FreeCAD.Vector(-r1, -r2, z), w) curve.setPole(3, FreeCAD.Vector(-r1, 0, z), 1) curve.setPole(4, FreeCAD.Vector(-r1, r2, z), w) curve.setPole(5, FreeCAD.Vector(0, r2, z), 1) curve.setPole(6, FreeCAD.Vector(r1, r2, z), w) curve.setPole(7, FreeCAD.Vector(r1, 0, z), 1) curve.setPole(8, FreeCAD.Vector(r1, -r2, z), w) fp.Shape = Part.Ellipse()
def execute(self, obj): pl = obj.Placement slabtype = obj.SlabType length = obj.Length.Value width = obj.Width.Value height = obj.Height.Value base = obj.SlabBase.Value holenumber = obj.HoleNumber holemajor = obj.HoleMajor.Value holeminor = obj.HoleMinor.Value holespacing = obj.HoleSpacing.Value slant = (height - base) / 3 # this gives the inclination of the vertical walls if (length == 0) or (width == 0) or (height == 0): return if base >= height: return if height < (base * 2): return if (holenumber > 0) and ((holespacing == 0) or (holemajor == 0) or (holeminor == 0)): return if holemajor < holeminor: return import Part p = [] if slabtype == "Champagne": p.append(Vector(0, 0, 0)) p.append(Vector(0, slant, height - base)) p.append(Vector(0, 0, height - base)) p.append(Vector(0, 0, height)) p.append(Vector(0, width, height)) p.append(Vector(0, width, height - base)) p.append(Vector(0, width - slant, height - base)) p.append(Vector(0, width, 0)) elif slabtype == "Hat": p.append(Vector(0, 0, 0)) p.append(Vector(0, 0, base)) p.append(Vector(0, slant, base)) p.append(Vector(0, slant * 2, height)) p.append(Vector(0, width - slant * 2, height)) p.append(Vector(0, width - slant, base)) p.append(Vector(0, width, base)) p.append(Vector(0, width, 0)) else: return None p.append(p[0]) p = Part.makePolygon(p) f = Part.Face(p) shape = f.extrude(Vector(length, 0, 0)) if holenumber > 0: holespan = holenumber * holeminor + (holenumber - 1) * holespacing holestart = (width / 2 - holespan / 2) + holeminor / 2 if holeminor != holemajor: e = Part.Ellipse(Vector(0, 0, 0), Vector(0, holeminor / 2, 0), Vector(0, 0, holemajor / 2)).toShape() e.translate(Vector(0, 0, -holemajor / 2)) else: e = Part.Circle(Vector(0, 0, 0), Vector(1, 0, 0), holemajor / 2).toShape() w = Part.Wire([e]) f = Part.Face(w) tube = f.extrude(Vector(length, 0, 0)) for i in range(holenumber): x = holestart + i * (holeminor + holespacing) s = tube.copy() s.translate(Vector(0, x, height / 2)) shape = shape.cut(s) shape = self.processSubShapes(obj, shape, pl) self.applyShape(obj, shape, pl)
def objArc(self, d, cx, cy, rx, ry, st, en, closed, node, mat): """ We ignore the path d, and produce a nice arc object. We distinguish two cases. If it looks like a circle, we produce ArcOfCircle, else we produce ArcOfEllipse. To find the arc end points, we use the value() property of the Circle and Ellipse objects. With Circle we have to take care of mirror and rotation ourselves. If closed, we connect the two ends to the center with lines. The connections are secured with constraints. Radii are currently not secured with constraints. """ ### CAUTION: Keep in sync with objEllipse() above. # print("objArc: st,en,closed", st, en, closed) self._matrix_from_svg(mat) c = self._from_svg(cx, cy, bbox=False) ori = self._from_svg(0, 0, bbox=False) vrx = self._from_svg(rx, 0, bbox=False) - ori vry = self._from_svg(0, ry, bbox=False) - ori i = self.ske.GeometryCount (st_idx, en_idx) = (1, 2) majAxisIdx = None if abs(vrx.Length - vry.Length) < epsilon: # it is a circle. self.bbox.add(c + vrx + vry) self.bbox.add(c - vrx - vry) ce = Part.Circle(Center=c, Normal=Base.Vector(0, 0, 1), Radius=vrx.Length) # Circles are immune to rotation and mirorring. Apply this manually. if self.yflip: (st, en) = (-en, -st) ## coord system is mirrored. else: (st, en) = (en, st) ## hmm. print("FIXME: ArcOfCircle() with yflip=False needs debugging.") r = Base.Matrix() r.rotateZ(st) pst = r.multiply(vrx) st = pst.getAngle(Base.Vector( 1, 0, 0)) # ce.rotateZ() is a strange beast. pst = pst + c r = Base.Matrix() r.rotateZ(en) pen = r.multiply(vrx) en = pen.getAngle(Base.Vector( 1, 0, 0)) # ce.rotateZ() is a strange beast. pen = pen + c self.ske.addGeometry([Part.ArcOfCircle(ce, st, en)]) self.stats['objArc'] += 1 else: # major axis is defined by Center and S1, # major radius is the distance between Center and S1, # minor radius is the distance between S2 and the major axis. s1 = self._from_svg(cx + rx, cy, bbox=False) s2 = self._from_svg(cx, cy + ry, bbox=False) (V1, V2, V3, V4) = self._ellipse_vertices2d(c, s1, s2) self.bbox.add(V1) self.bbox.add(V2) self.bbox.add(V3) self.bbox.add(V4) i = int(self.ske.GeometryCount) ce = Part.Ellipse(S1=V1, S2=V2, Center=c) self.ske.addGeometry([Part.ArcOfEllipse(ce, st, en)]) if self.expose_int: self.ske.exposeInternalGeometry(i) majAxisIdx = i + 1 # CAUTION: is that a safe assumption? self.stats['objArc'] += 1 ## CAUTION: with yflip=True sketcher reverses the endpoints of ## an ArcOfEllipse to: en=1, st=2 ## ArcOfCircle seems unaffected. if self.yflip: (st_idx, en_idx) = (2, 1) r = Base.Matrix() r.rotateZ(st) pst = r.multiply(vrx) + c r = Base.Matrix() r.rotateZ(en) pen = r.multiply(vrx) + c j = self.ske.GeometryCount if closed: self.ske.addGeometry([ Part.LineSegment(ce.value(en), c), Part.LineSegment(c, ce.value(st)) ]) if True: # when debugging deformations, switch off constriants first. self.ske.addConstraint([ Sketcher.Constraint('Coincident', i + 0, en_idx, j + 0, 1), # arc with line Sketcher.Constraint('Coincident', j + 1, 2, i + 0, st_idx), # line with arc Sketcher.Constraint('Coincident', j + 0, 2, j + 1, 1), # line with line Sketcher.Constraint('Coincident', j + 0, 2, i + 0, 3) ]) # line with center if False: # some debugging circles. self.ske.addGeometry( [ # Part.Circle(Center=pst, Normal=Base.Vector(0,0,1), Radius=2), # Part.Circle(Center=pen, Normal=Base.Vector(0,0,1), Radius=3), # Part.Circle(Center=ce.value(st), Normal=Base.Vector(0,0,1), Radius=4), Part.Circle(Center=ce.value(en), Normal=Base.Vector(0, 0, 1), Radius=5) ], True) # we return the start, end and center points, as triple (sketcher_index, sketcher_index_point, Vector) return ((i + 0, st_idx, ce.value(st)), (i + 0, en_idx, ce.value(en)), (i + 0, 3, c), majAxisIdx)
def geometriaElipse(self, centro = [0,0], radioMayor = [0,2], radioMenor = [1,0]): return Part.Ellipse(self.crearVector(radioMayor[0], radioMayor[1]),self.crearVector(radioMenor[0], radioMenor[1]),self.crearVector(centro[0],centro[1]))
def _render_pin_flange(label, datum_line, body, doc): Console.PrintMessage("_render_pin_flange({})\n".format(label)) # path for additive pipe pin_pipe_path_sketch = body.newObject("Sketcher::SketchObject", label + "_pin_pipe_path_sketch") pin_pipe_path_sketch.Support = [(datum_line.Support[1][0]), (datum_line, '')] pin_pipe_path_sketch.MapMode = 'OZX' # note 0.005 adjustment to prevent seemingly a bug in freecad rendering pin_pipe_path_sketch.AttachmentOffset = Placement( Vector(0, 0, ((-1 * DIMS_PIN_FLANGE_DEPTH) / 2) - 0.005), Rotation(0, 0, 0)) geometries = [] constraints = [] geometries.append( Part.Ellipse( Vector(DIMS_PIN_OUTER_RADIUS, 0, 0), Vector(0, -1 * (DIMS_PIN_OUTER_RADIUS - DIMS_PIN_FLANGE_HEIGHT), 0), Vector(0, 0, 0))) pin_pipe_path_sketch.addGeometry(geometries, False) pin_pipe_path_sketch.exposeInternalGeometry(0) # constrain ellipse position constraints.append( Sketcher.Constraint('Coincident', SKETCH_GEOMETRY_ORIGIN_INDEX, SKETCH_GEOMETRY_VERTEX_START_INDEX, 0, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX)) # constrain ellipse shape constraints.append(Sketcher.Constraint('Horizontal', 1)) constraints.append( Sketcher.Constraint('Distance', 1, 2 * DIMS_PIN_OUTER_RADIUS)) constraints.append( Sketcher.Constraint( 'Distance', 2, 2 * (DIMS_PIN_OUTER_RADIUS - DIMS_PIN_FLANGE_HEIGHT))) pin_pipe_path_sketch.addConstraint(constraints) doc.recompute() # profile for additive pipe pin_pipe_profile_sketch = body.newObject( "Sketcher::SketchObject", label + "_pin_pipe_profile_sketch") pin_pipe_profile_sketch.Support = [(pin_pipe_path_sketch, 'Edge1')] pin_pipe_profile_sketch.MapMode = 'ObjectXZ' geometries = [] constraints = [] geometries.append( Part.Ellipse(Vector(0, DIMS_PIN_FLANGE_DEPTH / 2, 0), Vector(-1 * DIMS_PIN_FLANGE_HEIGHT, 0, 0), Vector(0, 0, 0))) pin_pipe_profile_sketch.addGeometry(geometries, False) pin_pipe_profile_sketch.exposeInternalGeometry(0) # constrain ellipse position constraints.append( Sketcher.Constraint('DistanceX', SKETCH_GEOMETRY_ORIGIN_INDEX, SKETCH_GEOMETRY_VERTEX_START_INDEX, 0, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, DIMS_PIN_OUTER_RADIUS)) constraints.append( Sketcher.Constraint('DistanceY', SKETCH_GEOMETRY_ORIGIN_INDEX, SKETCH_GEOMETRY_VERTEX_START_INDEX, 0, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, 0)) # constrain ellipse shape constraints.append(Sketcher.Constraint('Horizontal', 2)) constraints.append( Sketcher.Constraint('Distance', 1, DIMS_PIN_FLANGE_DEPTH)) constraints.append( Sketcher.Constraint('Distance', 2, DIMS_PIN_FLANGE_HEIGHT * 2)) pin_pipe_profile_sketch.addConstraint(constraints) doc.recompute() # additive pipe for pin flange pin_pipe = body.newObject("PartDesign::AdditivePipe", label + "_pin_pipe") pin_pipe.Profile = pin_pipe_profile_sketch pin_pipe.Spine = pin_pipe_path_sketch doc.recompute() pin_pipe_path_sketch.ViewObject.Visibility = False pin_pipe_profile_sketch.ViewObject.Visibility = False return pin_pipe
def makeBCurveEdge(Points): geomCurve = Part.BezierCurve() geomCurve.setPoles(Points) edge = Part.Edge(geomCurve) return (edge) plane = Part.makePlane(2, 2) plane plane = Part.makePlane(2, 2, Base.Vector(3, 0, 0), Base.Vector(0, 1, 0)) plane.BoundBox Part.Ellipse() eli = Part.Ellipse(Base.Vector(10, 0, 0), Base.Vector(0, 5, 0), Base.Vector(0, 0, 0)) Part.show(eli.toShape()) eli = Part.Ellipse(Base.Vector(0, 0, 0), 10, 5) Part.show(eli.toShape()) torus = Part.makeTorus(10, 2) tor = Part.makeTorus(10, 5, Base.Vector(0, 0, 0), Base.Vector(0, 0, 1), 0, 180) tor = Part.makeTorus(10, 5, Base.Vector(0, 0, 0), Base.Vector(0, 0, 1), 0, 360, 180)
Radius=2), # North: math.pi/2 # SouthEast: -math.pi/4 # West: math.pi, -math.pi # East: 0 #Part.ArcOfCircle(Part.Circle(Base.Vector(4,7,0), Base.Vector(0,0,1), 1), math.pi/2, -math.pi) # # # Long axis SW: (N, -N, 0) # Short axis NE: (N, N, 0) # StartPoint North: 3/4 pi (counted CCW from long axis) # EndPoint NNE: -9/8 pi (counted CW from long axis) # FIXME: the angles are distroted according to the tangents of the contact point. # North is more like 5/8 pi but a bit less. Part.ArcOfEllipse( Part.Ellipse(App.Vector(8, -8, 0), App.Vector(3, 3, 0), App.Vector(0, 0, 0)), -math.pi * (8 + 1.) / 8, math.pi * (5. / 8)) # # Part.Ellipse(App.Vector(8,-8,0),App.Vector(3,3,0),App.Vector(0,0,0)) ] ske.addGeometry(geo, False) # False: normal, True: blue construction ske.exposeInternalGeometry(i + 5) # long and short axis, focal points of Ellipse print("GeometryCount changed from %d to %d" % (i, int(ske.GeometryCount))) con = [ Sketcher.Constraint('Coincident', i + 0, 2, i + 1, 1), Sketcher.Constraint('Coincident', i + 1, 2, i + 2, 1), Sketcher.Constraint('Coincident', i + 2, 2, i + 3, 1), Sketcher.Constraint('Coincident', i + 3, 2, i + 5, 2),
import Part from FreeCAD import Base ellipse1 = Part.Ellipse(Base.Vector(0, 0, 0), 1.0, 0.8) base1 = Part.Wire(Part.Edge(ellipse1)) ellipse2 = Part.Ellipse(Base.Vector(0, 0, 0), 0.8, 0.6) ellipse2.translate(Base.Vector(0, 0, 5)) tip1 = Part.Wire(Part.Edge(ellipse2)) side = Part.makeLoft([base1, tip1], True) ellipse3 = Part.Ellipse(Base.Vector(0, 0, 0), .8, 0.6) base2 = Part.Wire(Part.Edge(ellipse3)) ellipse4 = Part.Ellipse(Base.Vector(0, 0, 0), 0.6, 0.4) ellipse4.translate(Base.Vector(0, 0, 5)) tip2 = Part.Wire(Part.Edge(ellipse4)) core = Part.makeLoft([base2, tip2], True) Part.show(side) Part.show(core) App.ActiveDocument.addObject("Part::Cut", "Segment") App.ActiveDocument.Segment.Base = App.ActiveDocument.Shape App.ActiveDocument.Segment.Tool = App.ActiveDocument.Shape001 Gui.activeDocument.Shape.Visibility = False Gui.activeDocument.Shape001.Visibility = False