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


Python geometry.intersect_line_line方法代码示例

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


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

示例1: centerOfSphere

# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import intersect_line_line [as 别名]
def centerOfSphere(cls, fv):
        try:
            if len(fv) == 3:
                return G3.circumCenter(fv)  # Equator
            if len(fv) == 4:
                fv3 = [fv[0], fv[1], fv[2]]
                c1 = G3.circumCenter(fv)
                n1 = G3.ThreePnormal(fv)
                fv3 = [fv[1], fv[2], fv[3]]
                c2 = G3.circumCenter(fv3)
                n2 = G3.ThreePnormal(fv3)
                d1 = c1 + n1
                d2 = c2 + n2
                return geometry.intersect_line_line(c1, d1, c2, d2)[0]
        except(RuntimeError, TypeError):
            return None 
开发者ID:bcongdon,项目名称:bpy_lambda,代码行数:18,代码来源:geometry_utils.py

示例2: add_vertex_to_intersection

# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import intersect_line_line [as 别名]
def add_vertex_to_intersection():

    obj = bpy.context.object
    me = obj.data
    bm = bmesh.from_edit_mesh(me)

    edges = [e for e in bm.edges if e.select]

    if len(edges) == 2:
        [[v1, v2], [v3, v4]] = [[v.co for v in e.verts] for e in edges]

        iv = geometry.intersect_line_line(v1, v2, v3, v4)
        if iv:
            iv = (iv[0] + iv[1]) / 2
            bm.verts.new(iv)

            bm.verts.ensure_lookup_table()

            bm.verts[-1].select = True
            bmesh.update_edit_mesh(me) 
开发者ID:bcongdon,项目名称:bpy_lambda,代码行数:22,代码来源:V2X.py

示例3: centerOfSphere

# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import intersect_line_line [as 别名]
def centerOfSphere(cls, fv):
        try:
            if len(fv)==3:
                return G3.circumCenter(fv) # Equator
            if len(fv)==4:
                fv3 = [fv[0],fv[1],fv[2]]
                c1 = G3.circumCenter(fv)
                n1 = G3.ThreePnormal(fv)
                fv3 = [fv[1],fv[2],fv[3]]
                c2 = G3.circumCenter(fv3)
                n2 = G3.ThreePnormal(fv3)
                d1 = c1+n1
                d2 = c2+n2
                return geometry.intersect_line_line (c1, d1, c2, d2)[0]
        except(RuntimeError, TypeError):
            return None 
开发者ID:SelfAssembler,项目名称:BlenderCursorControl,代码行数:18,代码来源:geometry_utils.py

示例4: execute

# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import intersect_line_line [as 别名]
def execute(self, context):
        BlenderFake.forceUpdate()
        obj = bpy.context.active_object
        mat = obj.matrix_world

        se = [e for e in obj.data.edges if (e.select == 1)]
        e1v1 = obj.data.vertices[se[0].vertices[0]].co
        e1v2 = obj.data.vertices[se[0].vertices[1]].co
        e2v1 = obj.data.vertices[se[1].vertices[0]].co
        e2v2 = obj.data.vertices[se[1].vertices[1]].co

        qq = geometry.intersect_line_line(e1v1, e1v2, e2v1, e2v2)

        q = None
        if len(qq) == 0:
            # print ("lx 0")
            return {'CANCELLED'}

        if len(qq) == 1:
            # print ("lx 1")
            q = qq[0]

        if len(qq) == 2:
            cc = context.scene.cursor_control
            cc.cycleLinexCoice(2)
            q = qq[cc.linexChoice]

        # q = geometry.intersect_line_line (e1v1, e1v2, e2v1, e2v2)[qc] * mat
        # i2 = geometry.intersect_line_line (e2v1, e2v2, e1v1, e1v2)[0] * mat
        cc.setCursor(mat * q)

        return {'FINISHED'} 
开发者ID:bcongdon,项目名称:bpy_lambda,代码行数:34,代码来源:operators.py

示例5: orthoCenter

# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import intersect_line_line [as 别名]
def orthoCenter(cls, fv):
        try:
            h0 = G3.closestP2L(fv[0], fv[1], fv[2])
            h1 = G3.closestP2L(fv[1], fv[0], fv[2])
            # h2 = G3.closestP2L(fm[2], fm[0], fm[1])
            return geometry.intersect_line_line(fv[0], h0, fv[1], h1)[0]
        except(RuntimeError, TypeError):
            return None

    # Poor mans approach of finding center of circle 
开发者ID:bcongdon,项目名称:bpy_lambda,代码行数:12,代码来源:geometry_utils.py

示例6: get_intersection_dictionary

# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import intersect_line_line [as 别名]
def get_intersection_dictionary(bm, edge_indices):

    bm.verts.ensure_lookup_table()
    bm.edges.ensure_lookup_table()

    permutations = get_valid_permutations(bm, edge_indices)

    k = defaultdict(list)
    d = defaultdict(list)

    for edges in permutations:
        raw_vert_indices = cm.vertex_indices_from_edges_tuple(bm, edges)
        vert_vectors = cm.vectors_from_indices(bm, raw_vert_indices)

        points = LineIntersect(*vert_vectors)

        # some can be skipped.    (NaN, None, not on both edges)
        if can_skip(points, vert_vectors):
            continue

        # reaches this point only when an intersection happens on both edges.
        [k[edge].append(points[0]) for edge in edges]

    # k will contain a dict of edge indices and points found on those edges.
    for edge_idx, unordered_points in k.items():
        tv1, tv2 = bm.edges[edge_idx].verts
        v1 = bm.verts[tv1.index].co
        v2 = bm.verts[tv2.index].co
        ordered_points = order_points((v1, v2), unordered_points)
        d[edge_idx].extend(ordered_points)

    return d 
开发者ID:bcongdon,项目名称:bpy_lambda,代码行数:34,代码来源:XALL.py

示例7: line_from_edge_intersect

# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import intersect_line_line [as 别名]
def line_from_edge_intersect(edge1, edge2):
    '''
    > takes 2 tuples, each tuple contains 2 vectors
    - prepares input for sending to intersect_line_line
    < returns output of intersect_line_line
    '''
    [p1, p2], [p3, p4] = edge1, edge2
    return LineIntersect(p1, p2, p3, p4) 
开发者ID:bcongdon,项目名称:bpy_lambda,代码行数:10,代码来源:cad_module.py

示例8: _gen_meshface

# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import intersect_line_line [as 别名]
def _gen_meshface(self, points, bm):
        """
        points: list of (x,y,z) tuples
        bm: bmesh to add the (face-) points
        Used by the3dface() and solid()
        """

        def _is_on_edge(point):
            return abs(sum((e - point).length for e in (edge1, edge2)) - (edge1 - edge2).length) < 0.01

        points = list(points)

        i = 0
        while i < len(points):
            if points.count(points[i]) > 1:
                points.pop(i)
            else:
                i += 1

        verts = []
        for p in points:
            verts.append(bm.verts.new(self.proj(p)))
        face = bm.faces.new(verts)

        if len(points) == 4:
            for i in range(2):
                edge1 = verts[i].co
                edge2 = verts[i + 1].co
                opposite1 = verts[i + 2].co
                opposite2 = verts[(i + 3) % 4].co
                ii = geometry.intersect_line_line(edge1, edge2, opposite1, opposite2)
                if ii is not None:
                    if _is_on_edge(ii[0]):
                        bm.faces.remove(face)
                        iv = bm.verts.new(ii[0])
                        bm.faces.new((verts[i], iv, verts[(i + 3) % 4]))
                        bm.faces.new((verts[i + 1], iv, verts[i + 2])) 
开发者ID:scorpion81,项目名称:blender-addons,代码行数:39,代码来源:do.py

示例9: generate_3PT_mode_1_

# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import intersect_line_line [as 别名]
def generate_3PT_mode_1_(pts, obj):
    origin = obj.location
    transform_matrix = obj.matrix_local
    V = Vector

    # construction
    v1, v2, v3, v4 = V(pts[0]), V(pts[1]), V(pts[1]), V(pts[2])
    edge1_mid = v1.lerp(v2, 0.5)
    edge2_mid = v3.lerp(v4, 0.5)
    axis = geometry.normal(v1, v2, v4)
    mat_rot = mathutils.Matrix.Rotation(math.radians(90.0), 4, axis)

    # triangle edges
    v1_ = ((v1 - edge1_mid) * mat_rot) + edge1_mid
    v2_ = ((v2 - edge1_mid) * mat_rot) + edge1_mid
    v3_ = ((v3 - edge2_mid) * mat_rot) + edge2_mid
    v4_ = ((v4 - edge2_mid) * mat_rot) + edge2_mid

    r = geometry.intersect_line_line(v1_, v2_, v3_, v4_)
    if r:
        p1, _ = r
        # cp = transform_matrix * (p1 + origin)
        cp = transform_matrix * p1
        bpy.context.scene.cursor_location = cp
        # generate_gp3d_stroke(cp, axis, obj, radius=(p1-v1).length)
    else:
        print('not on a circle') 
开发者ID:mkbreuer,项目名称:ToolPlus,代码行数:29,代码来源:center_cursor.py

示例10: execute

# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import intersect_line_line [as 别名]
def execute(self, context):
        BlenderFake.forceUpdate()
        obj = bpy.context.active_object
        mat = obj.matrix_world

        se = [e for e in obj.data.edges if (e.select == 1)]
        e1v1 = obj.data.vertices[se[0].vertices[0]].co
        e1v2 = obj.data.vertices[se[0].vertices[1]].co
        e2v1 = obj.data.vertices[se[1].vertices[0]].co
        e2v2 = obj.data.vertices[se[1].vertices[1]].co

        qq = geometry.intersect_line_line (e1v1, e1v2, e2v1, e2v2)

        q = None
        if len(qq)==0:
            #print ("lx 0")
            return {'CANCELLED'}

        if len(qq)==1:
            #print ("lx 1")
            q = qq[0]

        if len(qq)==2:
            cc = context.scene.cursor_control
            cc.cycleLinexCoice(2)
            q = qq[cc.linexChoice]

        #q = geometry.intersect_line_line (e1v1, e1v2, e2v1, e2v2)[qc] * mat
        #i2 = geometry.intersect_line_line (e2v1, e2v2, e1v1, e1v2)[0] * mat
        cc.setDelta(mat*q)
        return {'FINISHED'} 
开发者ID:SelfAssembler,项目名称:BlenderCursorControl,代码行数:33,代码来源:operators.py

示例11: orthoCenter

# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import intersect_line_line [as 别名]
def orthoCenter(cls, fv):
        try:
            h0 = G3.closestP2L(fv[0], fv[1], fv[2])
            h1 = G3.closestP2L(fv[1], fv[0], fv[2])
            #h2 = G3.closestP2L(fm[2], fm[0], fm[1])
            return geometry.intersect_line_line (fv[0], h0, fv[1], h1)[0]
        except(RuntimeError, TypeError):
            return None

    # Poor mans approach of finding center of circle 
开发者ID:SelfAssembler,项目名称:BlenderCursorControl,代码行数:12,代码来源:geometry_utils.py

示例12: closestP2Cylinder

# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import intersect_line_line [as 别名]
def closestP2Cylinder(cls, p, fv):
        #print ("G3.closestP2Sphere")
        c = G3.closestP2CylinderAxis(p, fv)
        if c==None:
            return None
        r = (fv[0] - G3.centerOfSphere(fv)).length
        pc = p-c
        if pc.length == 0:
            pc = pc + Vector((1,0,0))
        else:
            pc.normalize()
        return c + (pc * r)

    #@classmethod
    #def closestP2Sphere4(cls, p, fv4):
        ##print ("G3.closestP2Sphere")
        #fv = [fv4[0],fv4[1],fv4[2]]
        #c1 = G3.circumCenter(fv)
        #n1 = G3.ThreePnormal(fv)
        #fv = [fv4[1],fv4[2],fv4[3]]
        #c2 = G3.circumCenter(fv)
        #n2 = G3.ThreePnormal(fv)
        #d1 = c1+n1
        #d2 = c2+n2
        #c = geometry.intersect_line_line (c1, d1, c2, d2)[0]
        #pc = p-c
        #if pc.length == 0:
            #pc = pc + Vector((1,0,0))
        #else:
            #pc.normalize()
        #return c + (pc * G3.distanceP2P(c, fv[0])) 
开发者ID:SelfAssembler,项目名称:BlenderCursorControl,代码行数:33,代码来源:geometry_utils.py

示例13: edgeIntersect

# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import intersect_line_line [as 别名]
def edgeIntersect(context, operator):
    from mathutils.geometry import intersect_line_line

    obj = context.active_object

    if (obj.type != "MESH"):
        operator.report({'ERROR'}, "Object must be a mesh")
        return None

    edges = []
    mesh = obj.data
    verts = mesh.vertices

    is_editmode = (obj.mode == 'EDIT')
    if is_editmode:
        bpy.ops.object.mode_set(mode='OBJECT')

    for e in mesh.edges:
        if e.select:
            edges.append(e)

            if len(edges) > 2:
                break

    if is_editmode:
        bpy.ops.object.mode_set(mode='EDIT')

    if len(edges) != 2:
        operator.report({'ERROR'},
                        "Operator requires exactly 2 edges to be selected")
        return

    line = intersect_line_line(verts[edges[0].vertices[0]].co,
                               verts[edges[0].vertices[1]].co,
                               verts[edges[1].vertices[0]].co,
                               verts[edges[1].vertices[1]].co)

    if line is None:
        operator.report({'ERROR'}, "Selected edges do not intersect")
        return

    point = line[0].lerp(line[1], 0.5)
    context.scene.cursor_location = obj.matrix_world * point


# Cursor Edge Intersection Operator # 
开发者ID:bcongdon,项目名称:bpy_lambda,代码行数:48,代码来源:space_view3d_toolshelf_menu.py

示例14: createOutline

# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import intersect_line_line [as 别名]
def createOutline(curve, outline):

    for spline in curve.data.splines[:]:
        p = spline.bezier_points
        out = []
        
        n = ((p[0].handle_right-p[0].co).normalized()-(p[0].handle_left-p[0].co).normalized()).normalized()
        n = Vector((-n[1], n[0], n[2]))
        o = p[0].co+outline*n
        out.append(o)
        
        for i in range(1,len(p)):
            n = ((p[i].handle_right-p[i].co).normalized()-(p[i].handle_left-p[i].co).normalized()).normalized()
            n = Vector((-n[1], n[0], n[2]))
            o = intersect_line_line(out[-1], (out[-1]+p[i].co-p[i-1].co), p[i].co, p[i].co+n)[0]
            out.append(o)
            
        curve.data.splines.new('BEZIER')
        if spline.use_cyclic_u:
            curve.data.splines[-1].use_cyclic_u = True
        p_out = curve.data.splines[-1].bezier_points
        p_out.add(len(out)-1)
    
        for i in range(len(out)):
            p_out[i].handle_left_type = 'FREE'  
            p_out[i].handle_right_type = 'FREE'
            
            p_out[i].co = out[i]
            
            if i<len(out)-1:
                l = (p[i+1].co-p[i].co).length
                l2 = (out[i]-out[i+1]).length
            
            if i==0:
                p_out[i].handle_left = out[i] + ((p[i].handle_left-p[i].co)*l2/l)
            if i<len(out)-1:
                p_out[i+1].handle_left = out[i+1] + ((p[i+1].handle_left-p[i+1].co)*l2/l)
            p_out[i].handle_right = out[i] + ((p[i].handle_right-p[i].co)*l2/l)
    
        for i in range(len(p)):
            p_out[i].handle_left_type = p[i].handle_left_type
            p_out[i].handle_right_type = p[i].handle_right_type
            
    return 
开发者ID:bcongdon,项目名称:bpy_lambda,代码行数:46,代码来源:curve_outline.py

示例15: _gen_meshface

# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import intersect_line_line [as 别名]
def _gen_meshface(self, points, bm):
        """
        points: list of (x,y,z) tuples
        bm: bmesh to add the (face-) points
        Used by the3dface() and solid()
        """

        def _is_on_edge(point):
            return abs(sum((e - point).length for e in (edge1, edge2)) - (edge1 - edge2).length) < 0.01

        points = list(points)

        i = 0
        while i < len(points):
            if points.count(points[i]) > 1:
                points.pop(i)
            else:
                i += 1

        verts = []
        for p in points:
            verts.append(bm.verts.new(self.proj(p)))

        # add only an edge if len points < 3
        if len(points) == 2:
            bm.edges.new(verts)
        elif len(points) > 2:
            face = bm.faces.new(verts)

            if len(points) == 4:
                for i in range(2):
                    edge1 = verts[i].co
                    edge2 = verts[i + 1].co
                    opposite1 = verts[i + 2].co
                    opposite2 = verts[(i + 3) % 4].co
                    ii = geometry.intersect_line_line(edge1, edge2, opposite1, opposite2)
                    if ii is not None:
                        if _is_on_edge(ii[0]):
                            try:
                                bm.faces.remove(face)
                            except Exception as e:
                                pass
                            iv = bm.verts.new(ii[0])
                            bm.faces.new((verts[i], iv, verts[(i + 3) % 4]))
                            bm.faces.new((verts[i + 1], iv, verts[i + 2])) 
开发者ID:bcongdon,项目名称:bpy_lambda,代码行数:47,代码来源:do.py


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