对于给定线条的给定列表,我想计算它的长度。例如:点的长度的长度
[(1,0),(5,6),(9,6),(5,2)]
这些只是连接点的列表。我怎样才能有一个自动化的方法来计算它们? 创造的线串代码:
import math
class Point(object):
def __init__(self, x, y):
self.x = x
self.y = y
class LineString(Point):
def __init__(self, *points):
#~ self.points=points
self.points = []
for point in points:
if not isinstance(point, Point):
point = Point(*point)
self.points.append(point)
if __name__ == '__main__':
# Tests for LineString
# ===================================
lin1 = LineString((1, 1), (0, 2))
assert lin1.length() == math.sqrt(2.0)
你能更多地讨论列表中实际包含什么? – justhalf
请提供列表示例和相应的预期结果。 – user3146587
好吧,我会添加代码在最小的 –