I have a circle with origin at (cx, cy). Radius is r. Then, there is a line segment defined by two points: (x1,y1) and (x2,y2). How to determine if the line segment (not the extended line) is tangent to the circle? And if yes, where do the two touch?
What I am doing now: find out the distance of the point (cx, cy) from the extended line. If the distance != r, then certainly the line segment is NOT tangent to circle. Even if the distance == r, then we need to find out the point where they touch. Then check whether that point lies on the segment between (x1,y1) and (x2,y2). If yes, the line segment IS tangent to the circle - and the touch point is computed already. This works but involves too much math. And all with float or double variables. Isn't there a smarter, faster algorithm to achieve same result?
Thanks and regards, Pramod