更新时间:2023-02-26 20:12:41
p1
code> p2 :
Distance between p1
and p2
:
CGFloat xDist = (p2.x - p1.x);
CGFloat yDist = (p2.y - p1.y);
CGFloat distance = sqrt((xDist * xDist) + (yDist * yDist));
背景:勾股定理
编辑:如果您只需要计算点之间的距离是增加还是减少, sqrt(),这将使它更快一点。
if you only need to calculate if the distance between the points increases or decreases, you can omit the sqrt() which will make it a little faster.