Can anyone help me create functions for doing this

1) three bool methods onCircle (Point *), outofCircle (Point *), and inCircle (Point *) for a Circle object C (so C->onCircle (P) for a point P means the point P lies on the circle C (i.e. the distance of P to the center of C is equal to the radius of C).

2) three bool method intersect (Circle *), tangent (Circle *), and disjoint (Circle *) to check if two circles intersect (in two points), are tangent (intersect in exactly one point), or are disjoint (do not intersect). For example, if we have Circle *C1, *C2; and Point *P; then C->inCircle (P) is true means point P is in the circle C; C1->intersect (C2) is true means circle C1 and C2 intersect.

3) Provide test cases for points on, inside, and outside a circle. Also provide cases for circles intersecting, tangent, and disjoint.

Additional information

Two circles intersect if the sum of their radii is larger than the distance between the two centers

Two circles are tangent if the sum of their radii is equal to the distance between the two centers

Two circles are disjoint if the sum of their radii is less than the distance between the two centers

Edited 6 Years Ago by Anocondo: n/a

The first thing you need to do is understand the mathametics. Use pencil & paper and work that out so that you know how to make the calculations.

Well first off do you have any code/pseudo code. I am surprised that you are going for pointers? (have you inherited from a shape class? and want to use a generic touching/intersect etc. However, that way you would not have onCircle but onShape.

I am not going to do this for you, so you are going to have to show some effort, but I am prepared to discuss a critical effect that you may have forgotten/overlooked, and that is accuracy.

It is only correct to say that two circle are tangent if they are EXACTLY on tangent and in the accuracy of computed numbers that is often surprisingly difficult to get.
So you are going to have to calculate the distance between the centres and the radius sum and subtract these two values, and they are considered to touch if they are within a certain distance. e.g

if (fabs(radiusSum-centre_centre_distance)<Tolerance)
   {
      // Circles touch
   }

However, your problems don't just end there, you have the additional problem that to compute the vector distance you are going to use squared numbers and that adds to you error (or a trig term e.g. tan, and that has its own errors). So yet more care is needed to avoid problems, unless the tolerance is large relative to roundoff.

Not what you wanted to hear I guess... but get some basic code together and present it, and we (that is the community here) will discuss it. You will learn a good bit, and I expect to as well.

Edited 6 Years Ago by StuXYZ: n/a

I agree with Stu, you need to post some sign of an effort.

Just a start-up idea, use a function (method) to compute the square-of-the-distance between two points (as in a method of class "point"), and you can pretty much use it for all the other methods.


@StuXYZ: you should add to your quote "experience is the most expensive way to learn anything, but it's the only way"

Edited 6 Years Ago by mike_2000_17: n/a

This article has been dead for over six months. Start a new discussion instead.