本文整理汇总了Python中Math.intersect_linesegs_ray方法的典型用法代码示例。如果您正苦于以下问题:Python Math.intersect_linesegs_ray方法的具体用法?Python Math.intersect_linesegs_ray怎么用?Python Math.intersect_linesegs_ray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Math
的用法示例。
在下文中一共展示了Math.intersect_linesegs_ray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calculate
# 需要导入模块: import Math [as 别名]
# 或者: from Math import intersect_linesegs_ray [as 别名]
def calculate(self, eye, radius, boundary):
"""Re-calculate the vision polygon.
WARNING: You should only call this if you want to re-calculate the vision polygon for some reason.
For normal usage, use L{get_vision} instead!
"""
self.cached_radius = radius
self.cached_position = eye
self.debug_points = []
self.debug_linesegs = []
radius_squared = radius * radius
closest_points = lambda points, reference: sorted(points, key=lambda p: (p - reference).get_length_squared())
def sub_segment(small, big):
return Math.distance_point_lineseg_squared(small[0], big[0], big[1]) < 0.0001 and Math.distance_point_lineseg_squared(small[1], big[0], big[1]) < 0.0001
def segment_in_obs(seg):
for line_segment in self.obs_segs:
if sub_segment(seg, line_segment):
return True
return False
def check_visibility(p):
bpoints = set(boundary.points)
if p not in bpoints:
if (eye - p).get_length_squared() > radius_squared: return False
if not boundary.contains_point(p): return False
for line_segment in obs_segs:
if Math.check_intersect_lineseg_lineseg( eye, p, line_segment[0], line_segment[1]):
if line_segment[0] != p and line_segment[1] != p:
return False
return True
def lineseg_in_radius(seg):
return Math.distance_point_lineseg_squared(eye, seg[0], seg[1]) <= radius_squared
obs_segs = filter(lineseg_in_radius, self.obs_segs)
# add all obstruction points and boundary points directly visible from the eye
visible_points = list(filter(check_visibility, set(self.obs_points + boundary.points )))
# find all obstructors intersecting the vision polygon
boundary_intersection_points = Math.intersect_linesegs_linesegs(obs_segs, zip(boundary.points, boundary.points[1:]) + [(boundary.points[-1], boundary.points[0])])
if self.debug: self.debug_points.extend([(p, 0xFF0000) for p in visible_points])
if self.debug: self.debug_points.extend([(p, 0x00FFFF) for p in boundary_intersection_points])
# filter boundary_intersection_points to only include visible points
# - need extra code here to handle points on obstructors!
for line_segment in obs_segs:
i = 0
while i < len(boundary_intersection_points):
p = boundary_intersection_points[i]
if Math.distance_point_lineseg_squared(p, line_segment[0], line_segment[1]) > 0.0001 and Math.check_intersect_lineseg_lineseg(eye, p, line_segment[0], line_segment[1]):
boundary_intersection_points.remove(p)
else:
i+=1
visible_points += boundary_intersection_points
poly = Math.Polygon()
poly.add_points(visible_points)
poly.sort_around(eye)
i = 0
while i < len(poly.points):
p = poly.points[i-1]
c = poly.points[i]
n = poly.points[ (i+1) % len(poly.points) ]
# intersect visible point with obstructors and boundary polygon
intersections = set(Math.intersect_linesegs_ray(obs_segs, eye, c) + Math.intersect_poly_ray(boundary.points, eye, c))
intersections = [ip for ip in intersections if ip != c and boundary.contains_point(ip)]
if self.debug: self.debug_points.extend([(pt, 0x00FF00) for pt in intersections])
if intersections:
intersection = min(intersections, key=lambda p: (p - eye).length_squared)
#if self.debug: self.debug_linesegs.append((0xFF00FF, [eye, intersection]))
#if self.debug: print "%d prev: %s current: %s next: %s" % (i, p, c, n)
sio_pc = segment_in_obs((p,c))
sio_cn = segment_in_obs((c,n))
if not sio_pc:
#.........这里部分代码省略.........