當前位置: 首頁>>代碼示例>>Python>>正文


Python Region.overlapRegion方法代碼示例

本文整理匯總了Python中region.Region.overlapRegion方法的典型用法代碼示例。如果您正苦於以下問題:Python Region.overlapRegion方法的具體用法?Python Region.overlapRegion怎麽用?Python Region.overlapRegion使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在region.Region的用法示例。


在下文中一共展示了Region.overlapRegion方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: intersect

# 需要導入模塊: from region import Region [as 別名]
# 或者: from region.Region import overlapRegion [as 別名]
	def intersect(self, other, pThresh=0):
		"""Determines the intersection point of self and other
		Arguments:
			other: [Segment] A segment
			pThresh: [float] The permitted error when testing for parallel
				lines (default: 0) 
		Returns: [List [Vector]] Empty list for no intersect, one Vector for a
			point-intersect, two for a segment-intersect 
		"""
		
		# Manually handles zero-length lines
		if self.len() == 0 or other.len() == 0: return [] 
		
		# Manually handles point overlaps
		if self == other: return [self.p1, self.p2]
		if self.p1 == other.p1 or self.p1 == other.p2: return []
		if self.p2 == other.p1 or self.p2 == other.p2: return []
		
		# Maps problem to problem of locating other's x-intersect
		toMove = self.p1.mul(-1)
		toRotate = -1 * self.angle()
		s1 = self.copy()
		s2 = other.copy()
		s1.move(toMove)
		s2.move(toMove)
		s1.rotate(toRotate)
		s2.rotate(toRotate)
		
		# No x-intersect -- s2 does not cross s1's line
		if abs(s2.p1.y) > pThresh and numpy.sign(s2.p1.y) == numpy.sign(s2.p2.y):
			return []
		
		# Segments are parallel
		if abs(s2.p1.y) <= pThresh and abs(s2.p1.y) <= pThresh:
			s1region = Region(s1.p1.x, s1.p2.x)
			s2region = Region(s2.p1.x, s2.p2.x)
			overlap = s1region.overlapRegion(s2region)
			
			if overlap is False:
				# No intersection
				return []
			else:
				# Calculates segment of intersection
				p1Intersect = fromPolar(overlap.left, self.angle()) \
					.add(self.p1)
				p2Intersect = fromPolar(overlap.len(), self.angle()) \
					.add(p1Intersect)
				return [p1Intersect, p2Intersect]
		
		# Calculates the x-intersect
		xIntersect = s2.p1.x + (s2.p2.x - s2.p1.x) * (s2.p1.y / (s2.p1.y - s2.p2.y))
		
		if not Region(s1.p1.x, s1.p2.x).contains(xIntersect):
			# No x-intersect -- s2 crosses s1's line out of range of s1
			return []
		
		# Calculates and returns the intersection point
		pIntersect = fromPolar(xIntersect, self.angle()).add(self.p1)
		return [pIntersect]
開發者ID:NicoAdams,項目名稱:SphericalCow,代碼行數:61,代碼來源:segment.py


注:本文中的region.Region.overlapRegion方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。