-1

I'm trying to write a program that lets the user put in the center point of a circle and its radius, and the put in two points to form a rectangle. Then I'm wanting it to print out whether the if the circle is touching/inside the rectangle in any way or not. I feel that I need to know all points the circle touches in order to know if its touching the or inside the rectangle at all.

Not sure if I made that completely clear, but any ideas?

1 Answers1

2

You're thinking about the problem in a harder way than is necessary. Once you know the rectangle, you know the four lines that form the boundary of the rectangle. Then the best way to proceed would to calculate the shortest distance from these lines to the center point of the circle. If this is greater than the radius, then the circle does not touch the rectangle. Otherwise, the circle does touch the rectangle.

Further, these computations are very simple.

Does that make sense?

  • it will help if the OP clarifies the problem, but I think what he has in mind is the "solid" circle (i.e., the interior as well as the perimeter) and the "solid" rectangle, and what he wants is to decide whether the two regions overlap based on their input descriptions. If so, then your answer is insufficient, because you might have a very small circle sitting in the middle of a large rectangle. – Barry Cipra Sep 13 '13 at 21:21