Python Part.makeCircle() Examples

The following are 23 code examples of Part.makeCircle(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module Part , or try the search function .
Example #1
Source File: paramVector.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def execute(self, obj):
        debug("\n* paramVector : execute *\n")
        if not hasattr(obj,"Origin"):
            v0 = FreeCAD.Vector(0,0,0)
        else:
            v0 = obj.Origin
        if not hasattr(obj,"Direction"):
            v1 = FreeCAD.Vector(0,0,-10)
        else:
            v1 = obj.Direction.normalize().multiply(10)
        v2 = v0.add(v1)
        line = Part.Edge(Part.LineSegment(v0,v2))
        cone = Part.makeCone(1,0,3,v2,v1,360)
        circle = Part.makeCircle(10,v0,v1.negative())
        face = Part.makeFace(circle,"Part::FaceMakerSimple")
        comp = Part.Compound([line,cone,face])
        obj.Shape = comp
        obj.ViewObject.Transparency = 50 
Example #2
Source File: TestCadObjects.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 6 votes vote down vote up
def testIntersect(self):
        """
        Tests finding the intersection of two faces.
        """
        # Face 1
        edge1 = Part.makeLine((0, 0, 0), (0, 10, 0))
        edge2 = Part.makeLine((0, 10, 0), (10, 10, 0))
        edge3 = Part.makeLine((10, 10, 0), (10, 0, 0))
        edge4 = Part.makeLine((10, 0, 0), (0, 0, 0))
        wire1 = Part.Wire([edge1,edge2,edge3,edge4])
        face1 = Part.Face(wire1)
        cqFace1 = Face(face1)

        # Face 2 (face to cut out of face 1)
        edge1 = Part.makeCircle(4.0)
        wire1 = Part.Wire([edge1])
        face2 = Part.Face(wire1)
        cqFace2 = Face(face2)

        # Face resulting from the intersection
        cqFace3 = cqFace1.intersect(cqFace2)

        self.assertEquals(len(cqFace3.Faces()), 1)
        self.assertEquals(len(cqFace3.Edges()), 3) 
Example #3
Source File: pipeFeatures.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def execute(self, fp):
    base=Part.Face(Part.Wire(Part.makeCircle(fp.D/2)))
    if fp.d>0:
      base=base.cut(Part.Face(Part.Wire(Part.makeCircle(fp.d/2))))
    if fp.n>0:
      hole=Part.Face(Part.Wire(Part.makeCircle(fp.f/2,FreeCAD.Vector(fp.df/2,0,0),FreeCAD.Vector(0,0,1))))
      hole.rotate(FreeCAD.Vector(0,0,0),FreeCAD.Vector(0,0,1),360.0/fp.n/2)
      for i in list(range(fp.n)):
        base=base.cut(hole)
        hole.rotate(FreeCAD.Vector(0,0,0),FreeCAD.Vector(0,0,1),360.0/fp.n)
    flange = base.extrude(FreeCAD.Vector(0,0,fp.t))
    try: # Flange2: raised-face and welding-neck
      if fp.trf>0 and fp.drf>0:
        rf=Part.makeCylinder(fp.drf/2,fp.trf,vO,vZ*-1).cut(Part.makeCylinder(fp.d/2,fp.trf,vO,vZ*-1))
        flange=flange.fuse(rf)
      if fp.dwn>0 and fp.twn>0 and fp.ODp>0:
        wn=Part.makeCone(fp.dwn/2,fp.ODp/2,fp.twn,vZ*float(fp.t)).cut(Part.makeCylinder(fp.d/2,fp.twn,vZ*float(fp.t)))
        flange=flange.fuse(wn)
    except:
      pass
    fp.Shape = flange
    fp.Ports=[FreeCAD.Vector(),FreeCAD.Vector(0,0,float(fp.t))]
    super(Flange,self).execute(fp) # perform common operations 
Example #4
Source File: TestCadObjects.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 6 votes vote down vote up
def testFuse(self):
        """
        Tests fusing one face to another.
        """
        # Face 1
        edge1 = Part.makeLine((0, 0, 0), (0, 10, 0))
        edge2 = Part.makeLine((0, 10, 0), (10, 10, 0))
        edge3 = Part.makeLine((10, 10, 0), (10, 0, 0))
        edge4 = Part.makeLine((10, 0, 0), (0, 0, 0))
        wire1 = Part.Wire([edge1,edge2,edge3,edge4])
        face1 = Part.Face(wire1)
        cqFace1 = Face(face1)

        # Face 2 (face to cut out of face 1)
        edge1 = Part.makeCircle(4.0)
        wire1 = Part.Wire([edge1])
        face2 = Part.Face(wire1)
        cqFace2 = Face(face2)

        # Face resulting from fuse
        cqFace3 = cqFace1.fuse(cqFace2)

        self.assertEquals(len(cqFace3.Faces()), 3)
        self.assertEquals(len(cqFace3.Edges()), 8) 
Example #5
Source File: FSNuts.py    From FreeCAD_FastenersWB with GNU General Public License v2.0 6 votes vote down vote up
def makeSquareTool(s, m):
  # makes a cylinder with an inner square hole, used as cutting tool
  # create square face
  msq = Base.Matrix()
  msq.rotateZ(math.radians(90.0))
  polygon = []
  vsq = Base.Vector(s / 2.0, s / 2.0, -m * 0.1)
  for i in range(4):
     polygon.append(vsq)
     vsq = msq.multiply(vsq)
  polygon.append(vsq)
  square = Part.makePolygon(polygon)
  square = Part.Face(square)

  # create circle face
  circ = Part.makeCircle(s * 3.0, Base.Vector(0.0, 0.0, -m * 0.1))
  circ = Part.Face(Part.Wire(circ))

  # Create the face with the circle as outline and the square as hole
  face=circ.cut(square)
 
  # Extrude in z to create the final cutting tool
  exSquare = face.extrude(Base.Vector(0.0, 0.0, m * 1.2))
  # Part.show(exHex)
  return exSquare 
Example #6
Source File: kicad.py    From fcad_pcb with MIT License 6 votes vote down vote up
def make_oval(size,params=None):
    _ = params
    if size.x == size.y:
        return make_circle(size)
    if size.x < size.y:
        r = size.x*0.5
        size.y -= size.x
        s  = ((0,0.5),(-0.5,0.5),(-0.5,-0.5),(0,-0.5),(0.5,-0.5),(0.5,0.5))
        a = (0,180,180,360)
    else:
        r = size.y*0.5
        size.x -= size.y
        s = ((-0.5,0),(-0.5,-0.5),(0.5,-0.5),(0.5,0),(0.5,0.5),(-0.5,0.5))
        a = (90,270,-90,-270)
    pts = [product(size,Vector(*v)) for v in s]
    return Part.Wire([
            Part.makeCircle(r,pts[0],Vector(0,0,1),a[0],a[1]),
            Part.makeLine(pts[1],pts[2]),
            Part.makeCircle(r,pts[3],Vector(0,0,1),a[2],a[3]),
            Part.makeLine(pts[4],pts[5])]) 
Example #7
Source File: shapes.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def makeCircle(cls, radius, center, normal):
        """
            Makes a Circle centered at the provided point, having normal in the provided direction
            :param radius: floating point radius of the circle, must be > 0
            :param center: vector representing the center of the circle
            :param normal: vector representing the direction of the plane the circle should lie in
            :return:
        """
        w = Wire(FreeCADPart.Wire([FreeCADPart.makeCircle(radius, center.wrapped, normal.wrapped)]))
        return w 
Example #8
Source File: shapes.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def makeCircle(cls, radius, pnt=(0, 0, 0), dir=(0, 0, 1), angle1=360.0, angle2=360):
        center = Vector(pnt)
        normal = Vector(dir)
        return Edge(FreeCADPart.makeCircle(radius, center.wrapped, normal.wrapped, angle1, angle2)) 
Example #9
Source File: TestCadObjects.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def testCopy(self):
        """
        Tests making a copy of a shape object and whether the new one has the
        same properties as the original.
        """
        e = Shape.cast(Part.makeCircle(2.0, FreeCAD.Base.Vector(1, 2, 3)))
        e2 = e.copy()

        self.assertEquals(e.BoundingBox().xlen, e2.BoundingBox().xlen)
        self.assertEquals(e.BoundingBox().ylen, e2.BoundingBox().ylen) 
Example #10
Source File: TestCadObjects.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def testTranslate(self):
        e = Shape.cast(Part.makeCircle(2.0, FreeCAD.Base.Vector(1, 2, 3)))
        e2 = e.translate(Vector(0, 0, 1))

        self.assertTupleAlmostEquals((1.0, 2.0, 4.0), e2.Center().toTuple(), 3) 
Example #11
Source File: TestCadObjects.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def testShapeInit(self):
        """
        Tests whether a Shape object can be instantiated without
        throwing an error.
        """
        e = Shape(Part.makeCircle(2.0, FreeCAD.Base.Vector(1, 2, 3))) 
Example #12
Source File: TestCadObjects.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def testEdgeWrapperMakeCircle(self):
        halfCircleEdge = Edge.makeCircle(radius=10, pnt=(0, 0, 0), dir=(0, 0, 1), angle1=0, angle2=180)

        self.assertTupleAlmostEquals((0.0, 5.0, 0.0), halfCircleEdge.CenterOfBoundBox(0.0001).toTuple(),3)
        self.assertTupleAlmostEquals((10.0, 0.0, 0.0), halfCircleEdge.startPoint().toTuple(), 3)
        self.assertTupleAlmostEquals((-10.0, 0.0, 0.0), halfCircleEdge.endPoint().toTuple(), 3) 
Example #13
Source File: TestCadObjects.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def testEdgeWrapperCenter(self):
        e = Edge(Part.makeCircle(2.0, FreeCAD.Base.Vector(1, 2, 3)))

        self.assertTupleAlmostEquals((1.0, 2.0, 3.0), e.Center().toTuple(), 3) 
Example #14
Source File: TestCadObjects.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def testShapeProps(self):
        """
        Tests miscellaneous properties of the shape object
        """
        e = Shape(Part.makeCircle(2.0, FreeCAD.Base.Vector(1, 2, 3)))

        # Geometry type
        self.assertEqual(e.geomType(), 'Edge')

        # Dynamic type checking
        self.assertTrue(e.isType(e, 'Edge'))
        self.assertFalse(e.isType(None, 'Edge'))

        # Checking null objects
        self.assertFalse(e.isNull())

        # Checking for sameness
        self.assertTrue(e.isSame(e))

        # Checking for equality
        self.assertTrue(e.isEqual(e))

        # Checking for shape validity
        self.assertTrue(e.isValid())

        # Testing whether shape is closed
        self.assertTrue(e.Closed())

        # Trying to get the area of the circular edge
        with self.assertRaises(ValueError):
            e.Area()

        # Getting the area of the square face
        mplane = Face.makePlane(10.0, 10.0)
        self.assertAlmostEqual(100.0, mplane.Area(), 3)

        # Getting the center of a solid
        s = Solid.makeCylinder(10.0, 10.0)
        self.assertTupleAlmostEquals((0.0, 0.0, 5.0), s.Center().toTuple(), 3) 
Example #15
Source File: Asm4_Measure.py    From FreeCAD_Assembly4 with GNU Lesser General Public License v2.1 5 votes vote down vote up
def drawCircle( self, radius, center, axis ):
        global taskUI
        cc = Part.makeCircle( radius, center, axis )
        circle = App.ActiveDocument.addObject('Part::FeaturePython', 'aCircle')
        #circle.ViewObject.Proxy = setCustomIcon(circle,'Draft_Circle.svg')
        circle.ViewObject.Proxy = setCustomIcon( circle, taskUI.circleIcon )
        circle.Shape = Part.Wire( cc )
        circle.ViewObject.LineWidth = 5
        circle.ViewObject.LineColor = ( 1.0, 1.0, 1.0 )
        circle.ViewObject.PointSize = 10
        circle.ViewObject.PointColor= ( 0.0, 0.0, 1.0 )
        self.addToDims(circle) 
Example #16
Source File: kicad.py    From fcad_pcb with MIT License 5 votes vote down vote up
def makeArc(center,start,angle):
    p = start.sub(center)
    r = p.Length
    a = -degrees(DraftVecUtils.angle(p))
    # NOTE: KiCAD pcb geometry runs in clockwise, while FreeCAD is CCW. So the
    # resulting arc below is the reverse of what's specified in kicad_pcb
    if angle>0:
        arc = Part.makeCircle(r,center,Vector(0,0,1),a-angle,a)
        arc.reverse();
    else:
        arc = Part.makeCircle(r,center,Vector(0,0,1),a,a-angle)
    return arc 
Example #17
Source File: kicad.py    From fcad_pcb with MIT License 5 votes vote down vote up
def make_gr_circle(params, width=0):
    center = makeVect(params.center)
    end = makeVect(params.end)
    r = center.distanceToPoint(end)
    if not width or r <= width*0.5:
        return Part.makeCircle(r+width*0.5, center)
    return Part.makeCompound([Part.Wire(Part.makeCircle(r+width*0.5,center)),
                              Part.Wire(Part.makeCircle(r-width*0.5,center,Vector(0,0,-1)))]) 
Example #18
Source File: kicad.py    From fcad_pcb with MIT License 5 votes vote down vote up
def make_circle(size,params=None):
    _ = params
    return Part.Wire(Part.makeCircle(size.x*0.5)) 
Example #19
Source File: pipeFeatures.py    From flamingo with GNU Lesser General Public License v3.0 5 votes vote down vote up
def execute(self, fp):
    fp.thread="M"+str(float(fp.d))
    c=Part.makeCircle(fp.C/2,FreeCAD.Vector(0,0,0),FreeCAD.Vector(0,0,1),0,180)
    l1=Part.makeLine((fp.C/2,0,0),(fp.C/2,fp.C/2-fp.H,0))
    l2=Part.makeLine((-fp.C/2,0,0),(-fp.C/2,fp.C/2-fp.H,0))
    p=Part.Face(Part.Wire(Part.makeCircle(fp.d/2,c.valueAt(c.FirstParameter),c.tangentAt(c.FirstParameter))))
    path=Part.Wire([c,l1,l2])
    fp.Shape=path.makePipe(p)
    fp.Ports=[FreeCAD.Vector(0,0,1)] 
Example #20
Source File: pipeFeatures.py    From flamingo with GNU Lesser General Public License v3.0 5 votes vote down vote up
def execute(self, fp):
    if fp.OD>fp.OD2:
      if fp.calcH or fp.Height==0:
        fp.Height=3*(fp.OD-fp.OD2)
      fp.Profile=str(fp.OD)+"x"+str(fp.OD2)
      if fp.conc:
        sol = Part.makeCone(fp.OD/2,fp.OD2/2,fp.Height)
        if fp.thk<fp.OD/2 and fp.thk2<fp.OD2/2:
          fp.Shape=sol.cut(Part.makeCone(fp.OD/2-fp.thk,fp.OD2/2-fp.thk2,fp.Height))
        else:
          fp.Shape=sol
        fp.Ports=[FreeCAD.Vector(),FreeCAD.Vector(0,0,float(fp.Height))]
      else:
        C=Part.makeCircle(fp.OD/2,FreeCAD.Vector(0,0,0),FreeCAD.Vector(0,0,1))
        c=Part.makeCircle(fp.OD2/2,FreeCAD.Vector(0,0,0),FreeCAD.Vector(0,0,1))
        c.translate(FreeCAD.Vector((fp.OD-fp.OD2)/2,0,fp.Height))
        sol=Part.makeLoft([c,C],True)
        if fp.thk<fp.OD/2 and fp.thk2<fp.OD2/2:
          C=Part.makeCircle(fp.OD/2-fp.thk,FreeCAD.Vector(0,0,0),FreeCAD.Vector(0,0,1))
          c=Part.makeCircle(fp.OD2/2-fp.thk2,FreeCAD.Vector(0,0,0),FreeCAD.Vector(0,0,1))
          c.translate(FreeCAD.Vector((fp.OD-fp.OD2)/2,0,fp.Height))
          fp.Shape=sol.cut(Part.makeLoft([c,C],True))
        else:
          fp.Shape=sol
        fp.Ports=[FreeCAD.Vector(),FreeCAD.Vector((fp.OD-fp.OD2)/2,0,float(fp.Height))]
    super(Reduct,self).execute(fp) # perform common operations 
Example #21
Source File: pipeFeatures.py    From flamingo with GNU Lesser General Public License v3.0 5 votes vote down vote up
def execute(self, fp):
    if fp.BendAngle<180:
      if fp.thk>fp.OD/2:
        fp.thk=fp.OD/2
      fp.ID=fp.OD-2*fp.thk
      fp.Profile=str(fp.OD)+"x"+str(fp.thk)
      CenterOfBend=FreeCAD.Vector(fp.BendRadius,fp.BendRadius,0)
      ## make center-line ##
      R=Part.makeCircle(fp.BendRadius,CenterOfBend,FreeCAD.Vector(0,0,1),225-float(fp.BendAngle)/2,225+float(fp.BendAngle)/2)
      ## move the cl so that Placement.Base is the center of elbow ##
      from math import pi, cos, sqrt
      d=(fp.BendRadius*sqrt(2)-fp.BendRadius/cos(fp.BendAngle/180*pi/2))
      P=FreeCAD.Vector(-d*cos(pi/4),-d*cos(pi/4),0)
      R.translate(P)
      ## calculate Ports position ##
      fp.Ports=[R.valueAt(R.FirstParameter),R.valueAt(R.LastParameter)]
      ## make the shape of the elbow ##
      c=Part.makeCircle(fp.OD/2,fp.Ports[0],R.tangentAt(R.FirstParameter)*-1)
      b=Part.makeSweepSurface(R,c)
      p1=Part.Face(Part.Wire(c))
      p2=Part.Face(Part.Wire(Part.makeCircle(fp.OD/2,fp.Ports[1],R.tangentAt(R.LastParameter))))
      sol=Part.Solid(Part.Shell([b,p1,p2]))
      planeFaces=[f for f in sol.Faces if type(f.Surface)==Part.Plane]
      #elbow=sol.makeThickness(planeFaces,-fp.thk,1.e-3)
      #fp.Shape = elbow
      if fp.thk<fp.OD/2:
        fp.Shape=sol.makeThickness(planeFaces,-fp.thk,1.e-3)
      else:
        fp.Shape=sol
      super(Elbow,self).execute(fp) # perform common operations 
Example #22
Source File: features.py    From freecad.gears with GNU General Public License v3.0 5 votes vote down vote up
def execute(self, fp):
        inner_diameter = fp.module.Value * fp.teeth
        outer_diameter = inner_diameter + fp.height.Value * 2
        inner_circle = Part.Wire(Part.makeCircle(inner_diameter / 2.))
        outer_circle = Part.Wire(Part.makeCircle(outer_diameter / 2.))
        inner_circle.reverse()
        face = Part.Face([outer_circle, inner_circle])
        solid = face.extrude(App.Vector([0., 0., -fp.thickness.Value]))

        # cutting obj
        alpha_w = np.deg2rad(fp.pressure_angle.Value)
        m = fp.module.Value
        t = fp.teeth
        t_c = t
        t_i = fp.other_teeth
        rm = inner_diameter / 2
        y0 = m * 0.5
        y1 = m + y0
        y2 = m
        r0 = inner_diameter / 2 - fp.height.Value * 0.1
        r1 = outer_diameter / 2 + fp.height.Value * 0.3
        polies = []
        for r_i in np.linspace(r0, r1, fp.num_profiles):
            pts = self.profile(m, r_i, rm, t_c, t_i, alpha_w, y0, y1, y2)
            poly = Wire(makePolygon(list(map(fcvec, pts))))
            polies.append(poly)
        loft = makeLoft(polies, True)
        rot = App.Matrix()
        rot.rotateZ(2 * np.pi / t)
        if fp.construct:
            cut_shapes = [solid]
            for _ in range(t):
                loft = loft.transformGeometry(rot)
                cut_shapes.append(loft)
            fp.Shape = Part.Compound(cut_shapes)
        else:
            for i in range(t):
                loft = loft.transformGeometry(rot)
                solid = solid.cut(loft)
            fp.Shape = solid 
Example #23
Source File: ribbon.py    From CurvesWB with GNU Lesser General Public License v2.1 4 votes vote down vote up
def main():
    obj1 = FreeCAD.ActiveDocument.getObject('CV_BAMB_ELEC_SING_Face25')
    f1 = obj1.Shape.Face1
    surf = f1.Surface
    mid = surf.vIso(0.5)
    c0 = surf.vIso(0.0)
    c1 = surf.vIso(1.0)
    v0 = c0.toShape()
    v1 = c1.toShape()
    num = 200
    inter = interp()
    inter.add(0,(c0.FirstParameter,c1.FirstParameter))
    pl = Part.Plane()
    for i in range(1,num):
        v = float(i)/num
        pt = mid.value(v)
        tan = mid.tangent(v)[0]
        pl.Position = pt
        pl.Axis = tan
        pts0 = c0.intersectCS(pl)[0]
        pts1 = c1.intersectCS(pl)[0]
        pt0 = closest_point(pts0,pt)
        pt1 = closest_point(pts1,pt)
        print(pt0,pt1)
        inter.add(v,(c0.parameter(pt0),c1.parameter(pt1)))
    inter.add(1,(c0.LastParameter,c1.LastParameter))
#        c = Part.makeCircle(0.3,pt,tan)
#        inf0 = c.distToShape(v0)[2][0]
#        inf1 = c.distToShape(v1)[2][0]
#        #print(inf0)
#        #print(inf1)
#        if inf0[3] == 'Edge' and inf1[3] == 'Edge':
#            inter.add(v,(inf0[5],inf1[5]))
    edges = list()
    for tu in zip(inter.param,inter.value):
        print(tu)
        l = Part.makeLine(v0.valueAt(tu[1][0]), v1.valueAt(tu[1][1]))
        edges.append(l)

    newc0 = Part.BSplineCurve()
    pts_0 = [v0.valueAt(v[0]) for v in inter.value]
    newc0.interpolate(Points = pts_0,Parameters=inter.param)
    Part.show(newc0.toShape())

    newc1 = Part.BSplineCurve()
    pts_1 = [v1.valueAt(v[1]) for v in inter.value]
    newc1.interpolate(Points = pts_1,Parameters=inter.param)
    Part.show(newc1.toShape())

    Part.show(Part.Compound(edges))