I need to find the closest distance between a box and a circle, however, I realize this can be broken up into the closest distance between a line segment and a circle.
Given
- I have a line segment of two points
point1_x
,point1_y
andpoint2_x
,point2_y
- I have a circle with center
circle_x
,circle_y
and radiusradius
Question
Is there a python library that will support this out of the box and if not can somebody present a function to do so?
(I belive I have to locate the tangent point on the circle with the same slope as the line?)
There exists a method to find the closest distance from circle to rectangle (axis-oriented here).
Rectangle sides divide plane into 9 pieces. We can find what piece (central, left-top, left etc) contains circle center, and calculate needed distance. Rectangle ABCD and circle center E:
Delphi code:
The euclid module. Install with:
Then use it like this: