本文整理汇总了Python中matplotlib.path.Path.intersects_path方法的典型用法代码示例。如果您正苦于以下问题:Python Path.intersects_path方法的具体用法?Python Path.intersects_path怎么用?Python Path.intersects_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.path.Path
的用法示例。
在下文中一共展示了Path.intersects_path方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Room
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import intersects_path [as 别名]
class Room(Location):
ltype = 'room'
priority = 2
def __init__(self, graph, name, level, titles, shape):
super().__init__(name, titles)
self.graph = graph
self.level = level
self.shape = shape
self.nodes = []
self.pois = []
self.barriers = []
self.groups = []
mpl_xy = self.shape+self.shape[-1:]
mpl_codes = [Path.MOVETO] + [Path.LINETO]*len(self.shape)
self.mpl_path = Path(np.array(mpl_xy), codes=mpl_codes)
@property
def priority(self):
return 1 if self.groups else 2
def contains_position(self, position):
if position.level != self.level:
return False
return self.mpl_path.contains_point((position.x, position.y))
def get_barriers(self):
return (b for b in self.graph.barriers
if b.level == self.level and self.mpl_path.intersects_path(b.mpl_path, True))
def barrier_paths(self):
return [self.mpl_path] + [b.mpl_path for b in self.barriers]
@property
def subtitle(self):
if not self.groups:
return _('Level %(level)d', level=self.level)
else:
return _('%(roomgroup)s, Level %(level)d', roomgroup=self.groups[0].collection_title, level=self.level)
def __repr__(self):
return 'Room(%s)' % repr(self.name)
示例2: traceArm2
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import intersects_path [as 别名]
def traceArm2(edgeMap, traceStart, vD, dir1, dir2, paths, shortestPaths=None, G=None, lineStart=None):
if lineStart is None:
lineStart = traceStart
dirvec = normalize(np.mean([normalize(dir1),normalize(dir2)],0))
maxAngle = abs(angle(dir1,dir2))/2
path = [start]
oldlength = 0
candidates = list(edgeMap[start].difference(path))
while len(candidates)>0:
angles = map(lambda x: abs(angle(vD.vertices[x,:]-vD.vertices[lineStart,:], dirvec, np.inf)), nodes)
newCoordinate = vD.vertices[candidates[np.argmin(angles)]]
newlength = np.linalg.norm(new-coordinate - vD.vertices[start])
curEdge = Path([vD.vertices[start], new-coordinate], [1, 2])
if np.any(map(lambda p: curEdge.intersects_path(p, False), paths)) or oldlength > newlength or min(angles) > maxAngle:
break
oldlength = newlength
path.append(candidates[np.argmin(angles)])
candidates = list(edgeMap[path[-1]].difference(path))
return path
示例3: test_path_intersect_path
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import intersects_path [as 别名]
def test_path_intersect_path():
# test for the range of intersection angles
base_angles = np.array([0, 15, 30, 45, 60, 75, 90, 105, 120, 135])
angles = np.concatenate([base_angles, base_angles + 1, base_angles - 1])
eps_array = [1e-5, 1e-8, 1e-10, 1e-12]
for phi in angles:
transform = transforms.Affine2D().rotate(np.deg2rad(phi))
# a and b intersect at angle phi
a = Path([(-2, 0), (2, 0)])
b = transform.transform_path(a)
assert a.intersects_path(b) and b.intersects_path(a)
# a and b touch at angle phi at (0, 0)
a = Path([(0, 0), (2, 0)])
b = transform.transform_path(a)
assert a.intersects_path(b) and b.intersects_path(a)
# a and b are orthogonal and intersect at (0, 3)
a = transform.transform_path(Path([(0, 1), (0, 3)]))
b = transform.transform_path(Path([(1, 3), (0, 3)]))
assert a.intersects_path(b) and b.intersects_path(a)
# a and b are collinear and intersect at (0, 3)
a = transform.transform_path(Path([(0, 1), (0, 3)]))
b = transform.transform_path(Path([(0, 5), (0, 3)]))
assert a.intersects_path(b) and b.intersects_path(a)
# self-intersect
assert a.intersects_path(a)
# a contains b
a = transform.transform_path(Path([(0, 0), (5, 5)]))
b = transform.transform_path(Path([(1, 1), (3, 3)]))
assert a.intersects_path(b) and b.intersects_path(a)
# a and b are collinear but do not intersect
a = transform.transform_path(Path([(0, 1), (0, 5)]))
b = transform.transform_path(Path([(3, 0), (3, 3)]))
assert not a.intersects_path(b) and not b.intersects_path(a)
# a and b are on the same line but do not intersect
a = transform.transform_path(Path([(0, 1), (0, 5)]))
b = transform.transform_path(Path([(0, 6), (0, 7)]))
assert not a.intersects_path(b) and not b.intersects_path(a)
# Note: 1e-13 is the absolute tolerance error used for
# `isclose` function from src/_path.h
# a and b are parallel but do not touch
for eps in eps_array:
a = transform.transform_path(Path([(0, 1), (0, 5)]))
b = transform.transform_path(Path([(0 + eps, 1), (0 + eps, 5)]))
assert not a.intersects_path(b) and not b.intersects_path(a)
# a and b are on the same line but do not intersect (really close)
for eps in eps_array:
a = transform.transform_path(Path([(0, 1), (0, 5)]))
b = transform.transform_path(Path([(0, 5 + eps), (0, 7)]))
assert not a.intersects_path(b) and not b.intersects_path(a)
# a and b are on the same line and intersect (really close)
for eps in eps_array:
a = transform.transform_path(Path([(0, 1), (0, 5)]))
b = transform.transform_path(Path([(0, 5 - eps), (0, 7)]))
assert a.intersects_path(b) and b.intersects_path(a)
# b is the same as a but with an extra point
a = transform.transform_path(Path([(0, 1), (0, 5)]))
b = transform.transform_path(Path([(0, 1), (0, 2), (0, 5)]))
assert a.intersects_path(b) and b.intersects_path(a)
return
示例4: Polygon
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import intersects_path [as 别名]
class Polygon(Region):
def __init__(self, lon_list, lat_list):
assert len(lon_list) == len(lat_list)
assert len(lon_list) > 2
# Check that input is a list
lon_list = list(lon_list)
lat_list = list(lat_list)
# Save the longitude and the latitude lists
self.__lon_list = lon_list
self.__lat_list = lat_list
# Ensure that the input is close
if lon_list[-1] != lon_list[0] or lat_list[-1] != lat_list[0]:
lon_list.append(lon_list[0])
lat_list.append(lat_list[0])
# Create a path object
codes = [Path.LINETO] * len(lon_list)
codes[0] = Path.MOVETO
codes[-1] = Path.CLOSEPOLY
coords = [ (lon_list[i], lat_list[i]) for i in range(len(lon_list))]
self.path = Path(coords, codes)
def is_inside(self, lon, lat):
points_coord = np.array((lon,lat)).T
reshaped = False
if len(points_coord.shape) < 2:
points_coord = points_coord.reshape(1,2)
reshaped = True
inside = self.path.contains_points(points_coord)
if reshaped:
return inside[0]
else:
return inside
@property
def border_latitudes(self):
return self.__lat_list
@property
def border_longitudes(self):
return self.__lon_list
@property
def borders(self):
output = []
for i in range(len(self.__lon_list)):
lon = self.border_longitudes[i]
lat = self.border_latitudes[i]
output.append((lon, lat))
return tuple(output)
def cross(self, another_region):
# The following lines are useful if another_region is a basin
if hasattr(another_region, "region"):
another_region = another_region.region
if isinstance(another_region, Polygon):
return np.bool_(self.path.intersects_path(another_region.path, filled=True))
elif isinstance(another_region, RegionUnion):
return another_region.cross(self)
elif isinstance(another_region, EmptyRegion):
return False
else:
raise NotImplementedError