Algorithm

Any one can guide me how to do that?
Design a Circle class and write a function to determine if 2 circles intersect
LVL 10
ukerandiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jmcgOwnerCommented:
Your circle class should contain methods or members that determine the x-y location of the centers and the radii. Two circles intersect if the distance between their centers is smaller than or equal to the sum of their radii but also larger than or equal to the smaller circle's radius.
0
anarki_jimbelSenior DeveloperCommented:
The example is not exactly what you need but it may give you an idea what a Circle class may look like:
http://www.krissteele.net/blogdetails.aspx?id=251

About the comment from jmcg above. I believe it is not quite correct.

First, we need to decide what "intersect" means. Because sometimes people mean that two circles "overlap". In this case the only condition is that two circles intersect if the distance between their centres is smaller than or equal to the sum of their radii.

If we are talking about circle line you may look at the example  http://csharphelper.com/blog/2014/09/determine-where-two-circles-intersect-in-c/.

Note that the condition "Two circles intersect if the distance between their centers is smaller than or equal to the sum of their radii but also larger than or equal to the smaller circle's radius" is NOT correct. The second part of the condition should be something like: "but also larger than or equal to the difference of radii). I.e. a small circle can be inside a big one.

You may also note some cases from the link I gave above.
"If d > r0 + r1: The circles are too far apart to intersect.
If d < |r0 – r1|: One circle is inside the other so there is no intersection.
If d = 0 and r0 = r1: The circles are the same.
If d = r0 + r1: The circles touch at a single point.
Otherwise: The circles touch at two points."

The last case - circles are next to each other.
Obviously, they are missing one case: d = |r0 – r1|! Citcles are inside each other and have one point of intersection.

Hope this helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jmcgOwnerCommented:
Good, Anarki, it's harder than I thought. Should have googled for an answer instead of thinking I knew it.
0
anarki_jimbelSenior DeveloperCommented:
In most tasks, I think, the first condition you gave  is 100% correct.
So your answer is good!
0
Gustav BrockCIOCommented:
> Should have googled for an answer instead of thinking I knew it.

No. Then you hadn't learned anything. You did it right.

/gustav
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.