Point::distance(Point &p2)
时间: 2023-12-29 18:03:50 浏览: 67
求两点距离(C语言)
5星 · 资源好评率100%
otherPoint) calculates the Euclidean distance between the current point and the point specified by the otherPoint parameter.
Here's an implementation in Python:
```
import math
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def distance(self, otherPoint):
dx = self.x - otherPoint.x
dy = self.y - otherPoint.y
return math.sqrt(dx**2 + dy**2)
```
This implementation uses the math module to calculate the square root of the sum of the squared differences between the x and y coordinates of the two points.
阅读全文