当前位置: 首页>>代码示例>>Python>>正文


Python Part.LineSegment方法代码示例

本文整理汇总了Python中Part.LineSegment方法的典型用法代码示例。如果您正苦于以下问题:Python Part.LineSegment方法的具体用法?Python Part.LineSegment怎么用?Python Part.LineSegment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Part的用法示例。


在下文中一共展示了Part.LineSegment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_profile_sketch

# 需要导入模块: import Part [as 别名]
# 或者: from Part import LineSegment [as 别名]
def make_profile_sketch(self):
        import Sketcher
        sk = FreeCAD.ActiveDocument.addObject('Sketcher::SketchObject','Profile')
        sk.Placement = FreeCAD.Placement(FreeCAD.Vector(0,0,0),FreeCAD.Rotation(0,0,0,1))
        sk.MapMode = "Deactivated"
        sk.addGeometry(Part.LineSegment(FreeCAD.Vector(100.0,0.0,0),FreeCAD.Vector(127.0,12.0,0)),False)
        sk.addConstraint(Sketcher.Constraint('PointOnObject',0,1,-1)) 
        sk.addGeometry(Part.ArcOfCircle(Part.Circle(FreeCAD.Vector(125.0,17.0,0),FreeCAD.Vector(0,0,1),5.8),-1.156090,1.050925),False)
        sk.addConstraint(Sketcher.Constraint('Tangent',0,2,1,1)) 
        sk.addGeometry(Part.LineSegment(FreeCAD.Vector(128.0,22.0,0),FreeCAD.Vector(100.0,37.0,0)),False)
        sk.addConstraint(Sketcher.Constraint('Tangent',1,2,2,1)) 
        sk.addConstraint(Sketcher.Constraint('Vertical',0,1,2,2)) 
        sk.addConstraint(Sketcher.Constraint('DistanceY',0,1,2,2,37.5)) 
        sk.setDatum(4,FreeCAD.Units.Quantity('35.000000 mm'))
        sk.renameConstraint(4, u'Lead')
        sk.setDriving(4,False)
        sk.addConstraint(Sketcher.Constraint('Equal',2,0)) 
        FreeCAD.ActiveDocument.recompute()
        return sk 
开发者ID:tomate44,项目名称:CurvesWB,代码行数:21,代码来源:HelicalSweepFP.py

示例2: compute_path_cp

# 需要导入模块: import Part [as 别名]
# 或者: from Part import LineSegment [as 别名]
def compute_path_cp(self):
        free_turns = self.turns-2
        skew = Part.LineSegment(Vector(2*pi,self.wire_diam,0),Vector((self.turns-1)*2*pi,self.length-self.wire_diam,0))
        tan = skew.tangent(skew.FirstParameter)[0]
        tan.normalize()
        tan.multiply(self.wire_diam/2.)
        p1 = Vector(-tan.y,tan.x,0)
        ls = Part.Line(skew.StartPoint+p1,skew.EndPoint-p1)
        h1 = Part.Line(Vector(0,self.wire_diam/2.,0),Vector(1,self.wire_diam/2.,0))
        h2 = Part.Line(Vector(0,self.length-self.wire_diam/2.,0),Vector(1,self.length-self.wire_diam/2.,0))
        pts = [Vector2d(0,self.wire_diam/2.)]
        i1 = h1.intersect(ls)[0]
        i2 = h2.intersect(ls)[0]
        pts.append(Vector2d(i1.X,i1.Y))
        pts.append(Vector2d(i2.X,i2.Y))
        pts.append(Vector2d(self.turns*2*pi,self.length-self.wire_diam/2.))
        return pts 
开发者ID:tomate44,项目名称:CurvesWB,代码行数:19,代码来源:comp_spring.py

示例3: addFaceBoundsToSketch

# 需要导入模块: import Part [as 别名]
# 或者: from Part import LineSegment [as 别名]
def addFaceBoundsToSketch(para_range, sk):
    geoList = list()
    conList = list()
    u0,u1,v0,v1 = para_range
    geoList.append(Part.LineSegment(vec(u0,v0,0),vec(u1,v0,0)))
    geoList.append(Part.LineSegment(vec(u1,v0,0),vec(u1,v1,0)))
    geoList.append(Part.LineSegment(vec(u1,v1,0),vec(u0,v1,0)))
    geoList.append(Part.LineSegment(vec(u0,v1,0),vec(u0,v0,0)))
    o = int(sk.GeometryCount)
    sk.addGeometry(geoList,False)
    
    conList.append(Sketcher.Constraint('Coincident',o+0,2,o+1,1))
    conList.append(Sketcher.Constraint('Coincident',o+1,2,o+2,1))
    conList.append(Sketcher.Constraint('Coincident',o+2,2,o+3,1))
    conList.append(Sketcher.Constraint('Coincident',o+3,2,o+0,1))
    conList.append(Sketcher.Constraint('Horizontal',o+0))
    conList.append(Sketcher.Constraint('Horizontal',o+2))
    conList.append(Sketcher.Constraint('Vertical',o+1))
    conList.append(Sketcher.Constraint('Vertical',o+3))
    conList.append(Sketcher.Constraint('DistanceX',o+2,2,o+2,1,u1-u0))
    conList.append(Sketcher.Constraint('DistanceY',o+1,1,o+1,2,v1-v0))
    conList.append(Sketcher.Constraint('DistanceX',o+0,1,-1,1,-u0)) 
    conList.append(Sketcher.Constraint('DistanceY',o+0,1,-1,1,-v0)) 
    sk.addConstraint(conList) 
开发者ID:tomate44,项目名称:CurvesWB,代码行数:26,代码来源:Sketch_On_Surface.py

示例4: __init__

# 需要导入模块: import Part [as 别名]
# 或者: from Part import LineSegment [as 别名]
def __init__(self, obj):
        """
            An Edge
        """
        self.wrapped = obj
        # self.startPoint = None
        # self.endPoint = None

        self.edgetypes = {
            FreeCADPart.ArcOfCircle: 'ARC',
            FreeCADPart.Circle: 'CIRCLE'
        }

        if hasattr(FreeCADPart,"Line"):
            self.edgetypes[FreeCADPart.Line] = 'LINE'

        if hasattr(FreeCADPart,"LineSegment"):
            self.edgetypes[FreeCADPart.LineSegment] = 'LINE'

         # Helps identify this solid through the use of an ID
        self.label = "" 
开发者ID:jmwright,项目名称:cadquery-freecad-module,代码行数:23,代码来源:shapes.py

示例5: line

# 需要导入模块: import Part [as 别名]
# 或者: from Part import LineSegment [as 别名]
def line(self, ed, p):
        e = self.getEdge(ed)
        pt = e.valueAt(p)
        t = e.tangentAt(p).multiply(100000)
        l = Part.LineSegment(pt,pt.add(t)).toShape()
        return(l) 
开发者ID:tomate44,项目名称:CurvesWB,代码行数:8,代码来源:ParametricBlendCurve.py

示例6: param

# 需要导入模块: import Part [as 别名]
# 或者: from Part import LineSegment [as 别名]
def param(self, par):
        if (par >= self.edge.FirstParameter) and  (par <= self.edge.LastParameter):
            self._par = par
            self.p1 = MarkerOnShape([self.edge.valueAt(self._par)],edge)
            tangent = self.edge.tangentAt(self._par) # TODO change tangent to cross-tangent
            tangent.normalize()
            tangent.multiply(1e12)
            l = Part.LineSegment(self.edge.valueAt(self._par).sub(tangent),self.edge.valueAt(self._par).add(tangent))
            self.tangent = l.toShape()
            self.p2 = MarkerOnShape([self.tangent.valueAt(self._scale)],self.tangent)
        else:
            FreeCAD.Console.PrintError("Bad parameter value, setting to middle of edge")
            self._par = self.edge.FirstParameter + 0.5 * (self.edge.LastParameter - self.edge.FirstParameter) 
开发者ID:tomate44,项目名称:CurvesWB,代码行数:15,代码来源:blendsurf_editor.py

示例7: getNotches

# 需要导入模块: import Part [as 别名]
# 或者: from Part import LineSegment [as 别名]
def getNotches(self, num=20, l=1.0):
        notches = list()
        for i in range(num):
            par = 1.0*i / (num-1)
            p1, p2 = self.valueAt(par)
            ls = Part.LineSegment(p1, p2)
            p3 = ls.value(ls.FirstParameter - l)
            p4 = ls.value(ls.LastParameter + l)
            nls = Part.makeLine(p3, p4)
            sh1 = self.rail1.face.project([nls])
            sh2 = self.rail2.face.project([nls])
            if (len(sh1.Edges) > 0) and (len(sh2.Edges) > 0):
                notches.append((sh1.Edges[0], sh2.Edges[0]))
        return(notches) 
开发者ID:tomate44,项目名称:CurvesWB,代码行数:16,代码来源:ribbon.py

示例8: execute

# 需要导入模块: import Part [as 别名]
# 或者: from Part import LineSegment [as 别名]
def execute(self, obj):
        e1,e2 = self.getEdges(obj)
        if (not e1) or (not e2):
            return()
        if hasattr(obj, "Parameter1") and hasattr(obj, "Parameter2") and hasattr(obj, "MainAxis"):
            l1 = Part.LineSegment(e1.valueAt(obj.Parameter1), e2.valueAt(obj.Parameter2))
            v = FreeCAD.Vector(obj.MainAxis)
            if v.Length < 1e-6:
                v = FreeCAD.Vector(0,0,1)
            direction = v.normalize().multiply(l1.length())
            obj.Shape = l1.toShape().extrude(direction)
        return() 
开发者ID:tomate44,项目名称:CurvesWB,代码行数:14,代码来源:ProfileSketch.py

示例9: execute

# 需要导入模块: import Part [as 别名]
# 或者: from Part import LineSegment [as 别名]
def execute(self, obj):
        v1 = _utils.getShape(obj, "Vertex1", "Vertex")
        v2 = _utils.getShape(obj, "Vertex2", "Vertex")
        if v1 and v2:
            l = Part.LineSegment(v1.Point, v2.Point)
            obj.Shape = l.toShape()
        else:
            FreeCAD.Console.PrintError("%s broken !\n"%obj.Label) 
开发者ID:tomate44,项目名称:CurvesWB,代码行数:10,代码来源:lineFP.py

示例10: isLine

# 需要导入模块: import Part [as 别名]
# 或者: from Part import LineSegment [as 别名]
def isLine(param):
    if hasattr(Part,"LineSegment"):
        return isinstance(param,(Part.Line,Part.LineSegment))
    else:
        return isinstance(param,Part.Line)
#------------------------------------------------------------------------------ 
开发者ID:kbwbe,项目名称:A2plus,代码行数:8,代码来源:a2plib.py

示例11: drawVector

# 需要导入模块: import Part [as 别名]
# 或者: from Part import LineSegment [as 别名]
def drawVector(fromPoint,toPoint, color):
    if fromPoint == toPoint: return
    doc = FreeCAD.ActiveDocument

    l = Part.LineSegment()
    l.StartPoint = fromPoint
    l.EndPoint = toPoint
    line = doc.addObject("Part::Feature","Line")
    line.Shape = l.toShape()
    line.ViewObject.LineColor = color
    line.ViewObject.LineWidth = 1

    
    c = Part.makeCone(0,1,4)
    cone = doc.addObject("Part::Feature","ArrowHead")
    cone.Shape = c
    cone.ViewObject.ShapeColor = color
    #
    mov = Base.Vector(0,0,0)
    zAxis = Base.Vector(0,0,-1)
    rot = FreeCAD.Rotation(zAxis,toPoint.sub(fromPoint))
    cent = Base.Vector(0,0,0)
    conePlacement = FreeCAD.Placement(mov,rot,cent)
    cone.Placement = conePlacement.multiply(cone.Placement)
    cone.Placement.move(toPoint)
    doc.recompute()
#------------------------------------------------------------------------------ 
开发者ID:kbwbe,项目名称:A2plus,代码行数:29,代码来源:a2plib.py

示例12: getFaceCompound

# 需要导入模块: import Part [as 别名]
# 或者: from Part import LineSegment [as 别名]
def getFaceCompound(shape,wire=False):
    objs = []
    for f in shape.Faces:
        selected = True
        for v in f.Vertexes:
            if not isZero(v.Z):
                selected = False
                break
        if not selected:
            continue

        ################################################################
        ## TODO: FreeCAD curve.normalAt is not implemented
        ################################################################
        # for e in f.Edges:
            # if isinstance(e.Curve,(Part.LineSegment,Part.Line)): continue
            # if not isZero(e.normalAt(Vector()).dot(Vector(0,0,1))):
                # selected = False
                # break
        # if not selected: continue

        if not wire:
            objs.append(f)
            continue
        for w in f.Wires:
            objs.append(w)
    if not objs:
        raise ValueError('null shape')
    return Part.makeCompound(objs) 
开发者ID:realthunder,项目名称:fcad_pcb,代码行数:31,代码来源:kicad.py

示例13: fix_two_cycle_sketch

# 需要导入模块: import Part [as 别名]
# 或者: from Part import LineSegment [as 别名]
def fix_two_cycle_sketch():
    """Return two-cycle sketch function object."""

    def aux_two_cycle_sketch(
        a=(20, 20, 0),
        b=(-30, 20, 0),
        c=(-30, -10, 0),
        d=(20, -10, 0),
        e=(50, 50, 0),
        f=(60, 50, 0),
        g=(55, 60, 0),
    ):
        """Helper function to drop a simple multi-cycle sketch.
           The segments are ordered into one rectangle and one triangle.
        """
        # Note: the z-component is zero, as sketches are plane objects.
        #       Adjust orientation with Sketch.Placement(Normal, Rotation)
        import Part
        import FreeCAD

        vec = FreeCAD.Vector
        lseg = Part.LineSegment

        doc = FreeCAD.ActiveDocument
        sketch = doc.addObject("Sketcher::SketchObject", "Sketch")
        sketch.addGeometry(lseg(vec(*a), vec(*b)), False)
        sketch.addGeometry(lseg(vec(*b), vec(*c)), False)
        sketch.addGeometry(lseg(vec(*c), vec(*d)), False)
        sketch.addGeometry(lseg(vec(*d), vec(*a)), False)

        sketch.addGeometry(lseg(vec(*e), vec(*f)), False)
        sketch.addGeometry(lseg(vec(*f), vec(*g)), False)
        sketch.addGeometry(lseg(vec(*g), vec(*e)), False)
        doc.recompute()
        return sketch

    return aux_two_cycle_sketch 
开发者ID:microsoft,项目名称:qmt,代码行数:39,代码来源:conftest.py

示例14: fix_rectangle_sketch

# 需要导入模块: import Part [as 别名]
# 或者: from Part import LineSegment [as 别名]
def fix_rectangle_sketch():
    """Return unit square sketch function object."""

    def aux_rectangle_sketch(x_length=1, y_length=1, x_start=0, y_start=0):
        """Helper function to drop a simple unit square sketch.
           The segments are carefully ordered.
        """
        import FreeCAD
        import Part

        vec = FreeCAD.Vector
        lseg = Part.LineSegment

        a = (x_start, y_start, 0)
        b = (x_length, y_start, 0)
        c = (x_length, y_length, 0)
        d = (x_start, y_length, 0)

        doc = FreeCAD.ActiveDocument
        sketch = doc.addObject("Sketcher::SketchObject", "Sketch")
        sketch.addGeometry(lseg(vec(*a), vec(*b)), False)
        sketch.addGeometry(lseg(vec(*b), vec(*c)), False)
        sketch.addGeometry(lseg(vec(*c), vec(*d)), False)
        sketch.addGeometry(lseg(vec(*d), vec(*a)), False)
        doc.recompute()
        return sketch

    return aux_rectangle_sketch 
开发者ID:microsoft,项目名称:qmt,代码行数:30,代码来源:conftest.py

示例15: addCycleSketch

# 需要导入模块: import Part [as 别名]
# 或者: from Part import LineSegment [as 别名]
def addCycleSketch(name, wire):
    """Add a sketch of a cycle (closed wire) to a FC document.

    Parameters
    ----------
    name :

    wire :


    Returns
    -------


    """
    assert wire.isClosed()
    doc = FreeCAD.ActiveDocument
    if doc.getObject(name) is not None:
        raise ValueError(f"Sketch with name '{name}' already exists.")

    # makeSketch() could handle constraints itself and does recompute() well,
    # but sometimes we may have invalid wires, which it handles badly (fixsometime)
    # ~ return Draft.makeSketch([wire], name=name, autoconstraints=True)

    sketch = doc.addObject("Sketcher::SketchObject", name)
    for i, edge in enumerate(wire.Edges):
        v0 = vec(tuple(edge.Vertexes[0].Point))
        v1 = vec(tuple(edge.Vertexes[1].Point))
        if i > 0:
            if (v0 - old_v1).Length > 1e-5:  # fix invalid wire segments
                v1 = vec(tuple(edge.Vertexes[0].Point))
                v0 = vec(tuple(edge.Vertexes[1].Point))
        old_v1 = v1
        sketch.addGeometry(Part.LineSegment(v0, v1))
        if i > 0:
            sketch.addConstraint(Sketcher.Constraint("Coincident", i - 1, 2, i, 1))
    sketch.addConstraint(Sketcher.Constraint("Coincident", i, 2, 0, 1))
    doc.recompute()
    return sketch 
开发者ID:microsoft,项目名称:qmt,代码行数:41,代码来源:sketchUtils.py


注:本文中的Part.LineSegment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。