已知七个点坐标,用python实现:选取其中一个点,求该点其余六点中任意两点组成的直线的距离,输出所有距离的值。然后取其他六点,重复上诉步骤
时间: 2024-03-01 21:54:18 浏览: 20
可以使用Python中的math库来计算两点之间的距离,具体实现如下:
```python
import math
def distance(p1, p2):
return math.sqrt((p1[0]-p2[0])**2 + (p1[1]-p2[1])**2)
points = [(1, 2), (3, 4), (5, 6), (7, 8), (9, 10), (11, 12), (13, 14)]
for p in points:
print(f"Distances for point {p}:")
for i in range(len(points)):
if points[i] != p:
for j in range(i+1, len(points)):
if points[j] != p:
d = distance(points[i], points[j])
print(f"Distance between {points[i]} and {points[j]}: {d}")
```
这段代码首先定义了一个计算两点之间距离的函数distance,然后遍历每一个点,对于每一个点,遍历剩余的点,选取任意两个点计算距离并输出。