本文整理匯總了Python中Point.Point.distance_to方法的典型用法代碼示例。如果您正苦於以下問題:Python Point.distance_to方法的具體用法?Python Point.distance_to怎麽用?Python Point.distance_to使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Point.Point
的用法示例。
在下文中一共展示了Point.distance_to方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from Point import Point [as 別名]
# 或者: from Point.Point import distance_to [as 別名]
class NodeMovement:
def __init__(self):
self.src = Point()
self.dest = Point()
self.src_time = 0.0
self.speed = 0.0
self.distance = 0.0
self.total_time = 0.0
self.dx = 0.0
self.dy = 0.0
def load_trace(self, trace):
l = trace.split()
self.src_time = float(l[1])
self.src.x = float(l[3][1:-1])
self.src.y = float(l[4][:-1])
self.src.z = float(l[5][:-2])
self.dest.x = float(l[6][1:-1])
self.dest.y = float(l[7][:-2])
self.speed = float(l[8])
self.distance = self.src.distance_to(self.dest)
self.total_time = self.distance / self.speed
self.dx = self.dest.x - self.src.x
self.dy = self.dest.y - self.src.y
def position_at(self, time):
dt = time - self.src_time
if dt > 0.0 and self.total_time > 0.0:
ratio = dt / self.total_time
p = Point()
p.x = self.src.x + self.dx * ratio
p.y = self.src.y + self.dy * ratio
return p
else:
return self.src