本文整理汇总了Python中geometry.Geometry.distance方法的典型用法代码示例。如果您正苦于以下问题:Python Geometry.distance方法的具体用法?Python Geometry.distance怎么用?Python Geometry.distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geometry.Geometry
的用法示例。
在下文中一共展示了Geometry.distance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from geometry import Geometry [as 别名]
# 或者: from geometry.Geometry import distance [as 别名]
def __init__(self, **kwargs):
Coordinate.__init__(self, **kwargs)
#半径
self.radius = kwargs['radius']
#角度
self.angle = kwargs.get('angle', 90.0)
#圆心
self.center = (0, 0)
x = Geometry.sin(self.angle / 2) * self.radius
y = Geometry.cos(self.angle / 2) * self.radius
self.source = x, y
self.target = -x, y
#外切圆心,外切半径
if self.angle < 90: #三点求圆
self.wrap_center = Geometry.circle_center(self.source, self.target, self.center)
self.wrap_radius = Geometry.distance(self.wrap_center, self.center)
elif self.angle < 180: #两侧点中点
self.wrap_center = (0, y)
self.wrap_radius = x
else: #所在的圆
self.wrap_center = self.center
self.wrap_radius = self.radius
示例2: wrap_collide
# 需要导入模块: from geometry import Geometry [as 别名]
# 或者: from geometry.Geometry import distance [as 别名]
def wrap_collide(self, shape):
for c1 in self.compose:
for c2 in shape.compose:
#先根据扇形和矩形自身的坐标调整
r1 = self.adjust(c1.adjust(c1.wrap_center)) #用缓存避免重复计算
r2 = shape.adjust(c2.adjust(c2.wrap_center))
distance = Geometry.distance(r1, r2)
if distance < c1.wrap_radius + c2.wrap_radius:
return True
return False
示例3: __init__
# 需要导入模块: from geometry import Geometry [as 别名]
# 或者: from geometry.Geometry import distance [as 别名]
def __init__(self, **kwargs):
Coordinate.__init__(self, **kwargs)
Motion.__init__(self, **kwargs)
#长度
self.length = kwargs['length']
middle = kwargs['middle']
#中间点,middle=0为圆
self.middle = (middle, self.length / 2)
#源点
self.source = (0, 0)
#目标点
if middle:
self.target = (0, self.length)
else:
self.target = self.source
#圆弧的圆心
if middle:
self.center = Geometry.circle_center(self.source, self.target, self.middle)
else:
self.center = self.middle
#半径
self.radius = Geometry.distance(self.source, self.center)
#角度
center_x, center_y = self.center
if middle > 0:
self.angle = 360 - 2 * Geometry.acos(center_x / self.radius)
elif middle < 0:
self.angle = 2 * Geometry.acos(center_x / self.radius)
else:
self.angle = 360
#距离
self.distance = Geometry.radian(self.angle) * self.radius
#上一个点
self.last_step = self.source