我正在构建一个与Google Places API交互的程序,以识别美国郡内某个类型的所有机构。谷歌接受半径形式的搜索 - 所以为了覆盖整个区域,我正在逐步建立我的搜索半径。但是,这个算法创建了很多重叠的圆圈,我想过滤掉。所以:
给出一个圆圈列表,每个圆圈的中心和半径,如何判断一个圆圈是否被其他圆圈的任何组合完全覆盖?
我已经可以判断一个圆圈是否被另一个圆圈包围 - 我的问题是很多圈子被其他几个圈子所包围。
有人要求我现有的代码 - 如果一个圆圈与另一个圆圈完全重叠而不是它们的组合,我目前测试的代码。但这就是我所拥有的。您可以看到,如果它与其他20个圆圈重叠,我可以将其排除在当前问题之外,此时它可能包含在内:
def radiusIsInsidePreviousQuery(self, testQuery):
newSearchCoordinates = (testQuery['center']['lat'], testQuery['center']['lng'])
alreadyBeenSearched = False
numberOfIntersectingCircles = 0
for queryNumber in self.results.keys():
previousQuery = self.results[queryNumber]
previousSearchCoordinates = (previousQuery['center']['lat'],
previousQuery['center']['lng'])
centroidDistance = VincentyDistance(newSearchCoordinates,
previousSearchCoordinates)
centroidDistanceMeters = centroidDistance.meters
newQueryRadius = testQuery['radius']
fullSearchDistance = centroidDistanceMeters + newQueryRadius
#If the full search distance (the sum of the distance between
#the two searches' centroids and the new search's radius) is less
#than the previous search's radius, then the new search is encompassed
#entirely by the old search.
previousQueryRadius = previousQuery['radius']
if fullSearchDistance <= previousQueryRadius:
print "Search area encompassed"
alreadyBeenSearched = True
elif centroidDistanceMeters < newQueryRadius + previousQueryRadius:
numberOfIntersectingCircles += 1
elif self.queriesAreEqual(testQuery, previousQuery):
print "found duplicate"
alreadyBeenSearched = True
#If it intersects with 20 other circles, it's not doing any more good.
if numberOfIntersectingCircles > 20:
alreadyBeenSearched = True
return alreadyBeenSearched
答案 0 :(得分:-1)
让我们考虑要测试的圆A.
我不知道你的计算需要多精确,但我们假设用100分代表A的周长就足够了。
导入数学
max(marglik{1})==marglik{1}