本文整理汇总了Python中mathutils.geometry.intersect_line_line函数的典型用法代码示例。如果您正苦于以下问题:Python intersect_line_line函数的具体用法?Python intersect_line_line怎么用?Python intersect_line_line使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了intersect_line_line函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: main
def main(context, vaxis, gpAxis):
axisdict = {"X": 0, "Y": 1, "Z": 2}
mesh = bpy.context.object
bm = bmesh.from_edit_mesh(mesh.data)
axis = axisdict[vaxis]
gpaxis = axisdict[gpAxis]
for vertice in bm.verts:
if vertice.select:
imen = -1000
imay = 1000
punto = vertice.co + mesh.location
jj = [point.co for point in bpy.context.object.grease_pencil.layers.active.frames[0].strokes[0].points]
for point in bpy.context.object.grease_pencil.layers.active.frames[0].strokes[-1].points:
if point.co[gpaxis] < punto[gpaxis] and point.co[gpaxis] > imen:
imen = point.co[gpaxis]
men = point.co
if point.co[gpaxis] > punto[gpaxis] and point.co[gpaxis] < imay:
imay = point.co[gpaxis]
may = point.co
try:
may
men
except:
print("wrong projection axis!")
break
if axis == 0:
try:
vertice.co = (
intersect_line_line(men, may, punto, (punto[0] + 1, punto[1], punto[2]))[0][0]
- mesh.location[0],
vertice.co.y,
vertice.co.z,
)
except:
pass
if axis == 1:
try:
vertice.co = (
vertice.co.x,
intersect_line_line(men, may, punto, (punto[0], punto[1] + 1, punto[2]))[0][1]
- mesh.location[1],
vertice.co.z,
)
except:
pass
if axis == 2:
try:
vertice.co = (
vertice.co.x,
vertice.co.y,
intersect_line_line(men, may, punto, (punto[0], punto[1], punto[2] + 1))[0][2]
- mesh.location[2],
)
except:
pass
bmesh.update_edit_mesh(mesh.data)
开发者ID:game-artist-rafael-nascimento,项目名称:BlenderAddons,代码行数:57,代码来源:oscurart_greasepencil_project.py
示例2: main
def main(context):
shape_ob = context.active_object
sel_spl = [spl for spl in get_selected_bezier_splines(shape_ob) if not spl.use_cyclic_u]
if sel_spl == None or len(sel_spl) == 0 or len(sel_spl) > 2:
print ("wrong selection")
return
# case of one endpoint selected
if len(sel_spl) == 1:
sel_pts = selected_endpoints(sel_spl[0])
if len(sel_pts) == 2:
p1, p1_handle = sel_pts
p1_extend = get_max_extent_2d(p1, p1_handle, get_shape_bounds(shape_ob))
p2 = nearest_point(p1, get_intersections(p1, p1_extend, shape_ob))
# case of two endpoints selected on the same spline
elif len(sel_pts) == 4:
p2 = intersect_line_line(sel_pts[1], sel_pts[0], sel_pts[3], sel_pts[2])[0]
else:
print ("wrong selection")
return
# case of two endpoints selected on seperate splines
if len(sel_spl) == 2:
sel_pts = selected_endpoints(sel_spl[0]) + selected_endpoints(sel_spl[1])
p2 = intersect_line_line(sel_pts[1], sel_pts[0], sel_pts[3], sel_pts[2])[0]
# add point to spline(s)
if p2 == None:
print ("no extension found")
else:
print ("extended point found on: ", p2)
if len(sel_spl) == 1:
if len(sel_pts) == 2:
bpy.ops.curve.handle_type_set(type='ALIGNED')
bpy.ops.curve.vertex_add(location=(p2.to_3d()+bpy.context.object.location))
bpy.ops.curve.handle_type_set(type='AUTOMATIC')
elif len(sel_pts) == 4:
bpy.ops.curve.handle_type_set(type='ALIGNED')
bpy.ops.curve.vertex_add()
sel_spl[0].bezier_points[0].co = p2.to_3d()
sel_spl[0].bezier_points[-1].co = p2.to_3d()
bpy.ops.curve.handle_type_set(type='AUTOMATIC')
elif len(sel_spl) == 2:
bpy.ops.curve.handle_type_set(type='ALIGNED')
bpy.ops.curve.vertex_add()
if sel_spl[0].bezier_points[0].select_control_point:
sel_spl[0].bezier_points[0].co = p2.to_3d()
else:
sel_spl[0].bezier_points[-1].co = p2.to_3d()
if sel_spl[1].bezier_points[0].select_control_point:
sel_spl[1].bezier_points[0].co = p2.to_3d()
else:
sel_spl[1].bezier_points[-1].co = p2.to_3d()
bpy.ops.curve.handle_type_set(type='AUTOMATIC')
开发者ID:mkbreuer,项目名称:ToolPlus,代码行数:54,代码来源:curve_extend.py
示例3: execute
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:Badcreature,项目名称:sagcg,代码行数:31,代码来源:operators.py
示例4: angleEnlarge
def angleEnlarge(c0, c1, c2, w):
try:
t = w[0] # variable width
except:
w = [w, w] # uniform offset
c0 = Vector(c0)
c1 = Vector(c1)
c2 = Vector(c2)
v0 = c1 - c0
v1 = c2 - c1
sz, rot = readVec(v0)
b = writeVec(w[0], rot - 90)
b = b + c0
c = b + v0
sz, rot = readVec(v1)
d = writeVec(w[1], rot - 90)
d = d + c1
e = d + v1
# TODO line_line always returns a tuple (never a None like line_2d)
interlist = geometry.intersect_line_line(b, c, d, e)
print(interlist)
if type(interlist) != type(None):
return interlist[0]
else:
return c
开发者ID:paulmotey,项目名称:Blended-Cities,代码行数:28,代码来源:geo.py
示例5: generate_3PT_mode_1_
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,代码行数:27,代码来源:ot_center.py
示例6: generate_3PT
def generate_3PT(pts, obj, nv, mode=1):
mw = obj.matrix_world
V = Vector
nv = max(3, nv)
# 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 = mw * p1
bpy.context.scene.cursor_location = cp
if mode == 0:
pass
elif mode == 1:
generate_bmesh_repr(p1, v1, axis, nv)
else:
print('not on a circle')
开发者ID:GordCaswell,项目名称:blenderportable,代码行数:32,代码来源:CCEN.py
示例7: solve_curvature
def solve_curvature(p1, p2, n1, n2, fac, fallback):
""" Add a nice circular curvature on
"""
from mathutils.geometry import (intersect_line_line,
)
p1_a = p1 + n1
p2_a = p2 - n2
isect = intersect_line_line(p1,
p1_a,
p2,
p2_a,
)
if isect:
corner = isect[0].lerp(isect[1], 0.5)
else:
corner = None
if corner:
p1_first_order = p1.lerp(corner, fac)
p2_first_order = corner.lerp(p2, fac)
co = p1_first_order.lerp(p2_first_order, fac)
return co
else:
# cant interpolate. just return interpolated value
return fallback.copy() # p1.lerp(p2, fac)
开发者ID:miklobit,项目名称:blenderpython,代码行数:29,代码来源:curve_utils.py
示例8: xsect_spline
def xsect_spline(sp_a, sp_b, _hubs, precision):
pt_a_prev = pt_b_prev = None
EPS_SPLINE = min(sp_a.length, sp_b.length) / precision
pt_a_prev = sp_a.points[0]
for a, pt_a in enumerate(sp_a.points[1:]):
pt_b_prev = sp_b.points[0]
for b, pt_b in enumerate(sp_b.points[1:]):
# Now we have 2 edges
# print(pt_a, pt_a_prev, pt_b, pt_b_prev)
xsect = intersect_line_line(pt_a, pt_a_prev, pt_b, pt_b_prev)
if xsect is not None:
if (xsect[0] - xsect[1]).length <= EPS_SPLINE:
f = intersect_point_line(xsect[1], pt_a, pt_a_prev)[1]
# if f >= 0.0-EPS_SPLINE and f <= 1.0+EPS_SPLINE:
# for some reason doesnt work so well, same below
if f >= 0.0 and f <= 1.0:
f = intersect_point_line(xsect[0], pt_b, pt_b_prev)[1]
# if f >= 0.0-EPS_SPLINE and f <= 1.0+EPS_SPLINE:
if f >= 0.0 and f <= 1.0:
# This wont happen often
co = xsect[0].lerp(xsect[1], 0.5)
hub = get_hub(co, _hubs, EPS_SPLINE)
sp_a.hubs.append((a, hub))
sp_b.hubs.append((b, hub))
pt_b_prev = pt_b
pt_a_prev = pt_a
开发者ID:Badcreature,项目名称:sagcg,代码行数:30,代码来源:retopo.py
示例9: orthoCenter
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
开发者ID:AndroidMove,项目名称:blender-architecture-scripts,代码行数:8,代码来源:geometry_utils.py
示例10: __init__
def __init__(self, wall, o):
self.wall = wall
self.o = o
# get neighbor EMPTYs for <o>
o2 = wall.getCornerEmpty(o)
self.o2 = o2
o1 = wall.getPrevious(o2)
self.o1 = o1
context = wall.context
# temporarily remove drivers for the segment EMPTY object
o.driver_remove("location")
# get neighbor EMPTYs for <o1> and <o2>
e1 = wall.getPrevious(o1)
attached1 = None if e1 else wall.getReferencesForAttached(o1)
self.attached1 = attached1
e2 = wall.getNext(o2)
attached2 = None if e2 else wall.getReferencesForAttached(o2)
self.attached2 = attached2
# vectors
if e1:
v1 = o1.location - e1.location
elif attached1:
v1 = attached1[1].location - attached1[0].location
if e2:
v2 = e2.location - o2.location
elif attached2:
v2 = attached2[1].location - attached2[0].location
p = None
if (e1 or attached1) and (e2 or attached2):
# check if v1 and v2 are parallel
if v1.normalized().cross(v2.normalized()).length < zero2:
# orient <o> along v1, which gives the same effect as orienting <o> along v2
dy, dx = v1.y, v1.x
else:
# point where the lines defined by v1 and v2 intersect
l1 = (e1, o1) if e1 else attached1
l2 = (o2, e2) if e2 else attached2
p = intersect_line_line(l1[0].location, l1[1].location, l2[0].location, l2[1].location)[0]
# orient <o> along the line defined by <o> and <p>
dy, dx = o.location.y-p.y, o.location.x-p.x
elif e1 or attached1 or e2 or attached2:
_v = v1 if e1 or attached1 else v2
# orient <o> along <_v>
dy, dx = _v.y, _v.x
else:
# orient <o> along the normal to the wall segment defined by <o>
dy, dx = o1.location.x-o2.location.x, o2.location.y-o1.location.y
o.rotation_euler[2] = math.atan2(dy, dx)
context.scene.update()
# adding drivers for o1 and o2
addMoverDrivers(o1, o, p)
addMoverDrivers(o2, o, p)
makeActiveSelected(context, o)
开发者ID:vvoovv,项目名称:prokitektura-studio,代码行数:58,代码来源:mover_segment.py
示例11: getIntersection
def getIntersection(x, y):
BMEdge = bmesh.types.BMEdge
x1, x2 = (x.verts[0].co, x.verts[1].co) if isinstance(x, BMEdge) else (x[0], x[1])
y1, y2 = (y.verts[0].co, y.verts[1].co) if isinstance(y, BMEdge) else (y[0], y[1])
if angle_2vec3(x1-x2, y1-y2) < 0.002:
return None
else:
vec = geometry.intersect_line_line(x1, x2, y1, y2)
return (vec[0] + vec[1]) / 2
开发者ID:mkbreuer,项目名称:ToolPlus,代码行数:9,代码来源:unbevel.py
示例12: grad_f_ed
def grad_f_ed(ed, p, last_face):
# walk around non manifold edges
if len(ed.link_faces) == 1:
minv = min(ed.verts, key=geos.get)
return minv.co, minv, None
f = [fc for fc in ed.link_faces if fc != last_face][0]
g = gradient_face(f, geos)
L = f.calc_perimeter()
# test for vert intersection
for v in f.verts:
v_inter, pct = intersect_point_line(v.co, p, p - L * g)
delta = v.co - v_inter
if delta.length < epsilon:
print("intersect vert")
return v.co, v, None
tests = [e for e in f.edges if e != ed]
for e in tests:
v0, v1 = intersect_line_line(e.verts[0].co, e.verts[1].co, p, p - L * g)
V = v0 - e.verts[0].co
edV = e.verts[1].co - e.verts[0].co
Vi = v0 - p
if V.length - edV.length > epsilon:
# print('intersects outside segment')
continue
elif V.dot(edV) < 0:
# print('intersects behind')
continue
elif Vi.dot(g) > 0: # remember we watnt to travel DOWN the gradient
# print('shoots out the face, not across the face')
continue
else:
# print('regular face edge crossing')
return v0, e, f
# we didn't intersect across an edge, or on a vert,
# therefore, we should travel ALONG the edge
vret = min(ed.verts, key=geos.get)
return vret.co, vret, None
开发者ID:patmo141,项目名称:cut_mesh,代码行数:52,代码来源:geodesic.py
示例13: persp_fac_to_world_fac
def persp_fac_to_world_fac(self, fac, inverted_perspective_matrix, v1, v2):
"""v1,v2はpersp座標"""
v3 = v1 + (v2 - v1) * fac
v4 = v3.copy()
v3[2] = 0.0
v4[2] = 0.5
vec1 = mul_persp(inverted_perspective_matrix, v1)
vec2 = mul_persp(inverted_perspective_matrix, v2)
vec3 = mul_persp(inverted_perspective_matrix, v3)
vec4 = mul_persp(inverted_perspective_matrix, v4)
i1, i2 = geo.intersect_line_line(vec1, vec2, vec3, vec4)
vec12 = vec2 - vec1
return vec12.dot(i1 - vec1) / vec12.length ** 2
开发者ID:Italic-,项目名称:blenderpython,代码行数:13,代码来源:_mesh_fake_knife.py
示例14: generate_3PT_mode_1
def generate_3PT_mode_1(pts=None, num_verts=20, make_edges=False):
'''
Arc from start - throught - Eend
- call this function only if you have 3 pts,
- do your error checking before passing to it.
'''
num_verts -= 1
verts, edges = [], []
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:
# do arc
p1, _ = r
# find arc angle.
a = (v1 - p1).angle((v4 - p1), 0)
s = (2 * math.pi) - a
interior_angle = (v1 - v2).angle(v4 - v3, 0)
if interior_angle > 0.5 * math.pi:
s = math.pi + 2 * (0.5 * math.pi - interior_angle)
for i in range(num_verts + 1):
mat_rot = mathutils.Matrix.Rotation(((s / num_verts) * i), 4, axis)
vec = ((v4 - p1) * mat_rot) + p1
verts.append(vec[:])
else:
# do straight line
step_size = 1 / num_verts
verts = [v1_.lerp(v4_, i * step_size)[:] for i in range(num_verts + 1)]
if make_edges:
edges = [(n, n + 1) for n in range(len(verts) - 1)]
return verts, edges
开发者ID:nortikin,项目名称:sverchok,代码行数:49,代码来源:basic_3pt_arc.py
示例15: center_of_circumscribed_circle_tri
def center_of_circumscribed_circle_tri(v1, v2, v3):
"""三角形の外接円の中心点を求める"""
if v1 != v2 and v2 != v3 and v3 != v1:
# 垂直二等分線の交差点を求める
v12 = v2 - v1
v13 = v3 - v1
med12 = (v1 + v2) / 2
med13 = (v1 + v3) / 2
per12 = v13 - v13.project(v12)
per13 = v12 - v12.project(v13)
inter = geom.intersect_line_line(med12, med12 + per12,
med13, med13 + per13)
if inter:
return (inter[0] + inter[1]) / 2
return None
开发者ID:Italic-,项目名称:blenderpython,代码行数:15,代码来源:vamath.py
示例16: add_vertex_to_intersection
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)
iv = (iv[0] + iv[1]) / 2
bm.verts.new(iv)
bmesh.update_edit_mesh(me)
开发者ID:MartanLV,项目名称:blender_odeon,代码行数:15,代码来源:crosspointOnTwoEdges.py
示例17: get_intersection_dictionary
def get_intersection_dictionary(cm, bm, edge_indices):
bm.verts.ensure_lookup_table()
bm.edges.ensure_lookup_table()
permutations = get_valid_permutations(cm, bm, edge_indices)
k = defaultdict(list)
d = defaultdict(list)
for edges in permutations:
vert_vectors = cm.vectors_from_edges_tuple(bm, edges)
v1, v2, v3, v4 = vert_vectors
# Edges obviously can not intersect if their bounding
# boxes do not intersect
if (max(v1.x, v2.x) < min(v3.x, v4.x) or
max(v1.y, v2.y) < min(v3.y, v4.y) or
max(v1.z, v2.z) < min(v3.z, v4.z)):
continue
if (max(v3.x, v4.x) < min(v1.x, v2.x) or
max(v3.y, v4.y) < min(v1.y, v2.y) or
max(v3.z, v4.z) < min(v1.z, v2.z)):
continue
# Edges can not intersect if they do not lie in
# the same plane
if not cm.is_coplanar(vert_vectors):
continue
points = intersect_line_line(*vert_vectors)
# some can be skipped. (NaN, None, not on both edges)
if can_skip(cm, 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:nortikin,项目名称:sverchok,代码行数:48,代码来源:edges_intersect_mk2.py
示例18: grad_v
def grad_v(v):
"""
walk down from a vert
"""
eds = [ed for ed in v.link_edges if geos[ed.other_vert(v)] <= geos[v]]
if len(eds) == 0:
print("lowest vert or local minima")
return None, None, None
fs = set()
for ed in eds:
fs.update(ed.link_faces)
minf = min(fs, key=lambda x: sum([geos[vrt] for vrt in x.verts]))
for ed in minf.edges:
if v not in ed.verts:
g = gradient_face(minf, geos)
L = minf.calc_perimeter()
v0, v1 = intersect_line_line(ed.verts[0].co, ed.verts[1].co, v.co, v.co - L * g)
V = v0 - ed.verts[0].co
edV = ed.verts[1].co - ed.verts[0].co
if V.length - edV.length > epsilon:
continue
# print('intersects outside segment')
elif V.dot(edV) < 0:
# print('intersects behind')
continue
else:
# print('regular edge crossing')
return v0, ed, minf
# we were not able to walk through a face
print("must walk on edge")
vs = [ed.other_vert(v) for ed in eds]
minv = min(vs, key=geos.get)
if geos[minv] > geos[v]:
print("Found smallest geodesic already")
return None, None, None
return minv.co, minv, None
开发者ID:patmo141,项目名称:cut_mesh,代码行数:48,代码来源:geodesic.py
示例19: centerOfSphere
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:AndroidMove,项目名称:blender-architecture-scripts,代码行数:16,代码来源:geometry_utils.py
示例20: SegmentIntersect
def SegmentIntersect(A, B, C, D, point=True, more=False, pdeb=False):
A, B, C, D = Vectors([A, B, C, D])
# "l,dAB=readVec(B-A)
# l,dBA=readVec(A-B)
# l,dCD=readVec(D-C)
dec = 0.03
# if cfloat(dAB,'not',dCD,dec) and cfloat(dBA,'not',dCD,dec) :
if parallel(A, B, C, D, False) == False:
if (signedarea(A, B, C) * signedarea(A, B, D) <= 0) and (signedarea(C, D, A) * signedarea(C, D, B) <= 0):
# inter=LineIntersect(A,B,C,D)
inter = geometry.intersect_line_line(A, B, C, D)
# if (AB)=(CD) : return none
# if type(inter)!=type(tuple()) :
# if pdeb :print 'nonetype'
# return False
# if (AB)=(CD) bis : return -1.#IND
# elif str(inter[0][0])=='-1.#IND' :
# if pdeb :print '-1#IND'
# return False
# if (AB)=(CD) : return none
if type(inter) != type(tuple()) or str(inter[0][0]) == "nan":
if pdeb:
dprint("parrallel")
return False
# inter is equal to A,B,C or D : shall we include them ?
elif point == False and (
cfloat(inter[0], "eq", A, dec)
or cfloat(inter[0], "eq", B, dec)
or cfloat(inter[0], "eq", C, dec)
or cfloat(inter[0], "eq", D, dec)
):
if pdeb:
dprint("canceled : %s is an extremity" % inter[0])
return False
# ok
else:
return inter
elif pdeb:
dprint("segments")
# segments doesn't cross ( parralel or merged )
elif more:
if pdeb:
dprint("parallels")
return False, True
return False
开发者ID:paulmotey,项目名称:Blended-Cities,代码行数:47,代码来源:geo.py
注:本文中的mathutils.geometry.intersect_line_line函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论