I want to calculate the distance between two points in Java

后端 未结 7 1440
花落未央
花落未央 2020-12-29 21:31

OK, so I\'ve written most of a program that will allow me to determine if two circles overlap.

I have no problems whatsoever with my program aside from one issue: t

7条回答
  •  执念已碎
    2020-12-29 22:03

    Based on the @trashgod's comment, this is the simpliest way to calculate distance:

    double distance = Math.hypot(x1-x2, y1-y2);
    

    From documentation of Math.hypot:

    Returns: sqrt(x²+ y²) without intermediate overflow or underflow.

提交回复
热议问题