Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #3317 > unrolled thread

Programming question determining two circle's relation

Started bybyhesed <byhesed@gmail.com>
First post2011-04-30 01:33 -0700
Last post2011-04-30 11:49 -0700
Articles 14 — 5 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  Programming question determining two circle's relation byhesed <byhesed@gmail.com> - 2011-04-30 01:33 -0700
    Re: Programming question determining two circle's relation byhesed <byhesed@gmail.com> - 2011-04-30 01:59 -0700
      Re: Programming question determining two circle's relation "Gavino" <invalid@invalid.invalid> - 2011-04-30 17:51 +0200
        Re: Programming question determining two circle's relation byhesed <byhesed@gmail.com> - 2011-04-30 09:01 -0700
          Re: Programming question determining two circle's relation "Gavino" <invalid@invalid.invalid> - 2011-04-30 18:33 +0200
      Re: Programming question determining two circle's relation byhesed <byhesed@gmail.com> - 2011-04-30 02:03 -0700
    Re: Programming question determining two circle's relation byhesed <byhesed@gmail.com> - 2011-04-30 02:50 -0700
      Re: Programming question determining two circle's relation byhesed <byhesed@gmail.com> - 2011-04-30 08:42 -0700
        Re: Programming question determining two circle's relation "Gavino" <invalid@invalid.invalid> - 2011-04-30 17:59 +0200
      Re: Programming question determining two circle's relation "John B. Matthews" <nospam@nospam.invalid> - 2011-04-30 17:25 -0400
        Re: Programming question determining two circle's relation Patricia Shanahan <pats@acm.org> - 2011-04-30 17:03 -0700
          Re: Programming question determining two circle's relation "John B. Matthews" <nospam@nospam.invalid> - 2011-05-01 03:10 -0400
    Re: Programming question determining two circle's relation Patricia Shanahan <pats@acm.org> - 2011-04-30 02:08 -0700
    Re: Programming question determining two circle's relation Roedy Green <see_website@mindprod.com.invalid> - 2011-04-30 11:49 -0700

#3317 — Programming question determining two circle's relation

Frombyhesed <byhesed@gmail.com>
Date2011-04-30 01:33 -0700
SubjectProgramming question determining two circle's relation
Message-ID<892252a0-e31d-426b-8f47-d37c0b2ec364@17g2000prr.googlegroups.com>
What's wrong with contains and overlaps method in Circle2D class?
It returns incorrect answers.

- A method contains(double x, double y) returns true if the specified
point(x,y) is inside this circle.
- A method contains(Circle2D circle) returns true if the specified
circle is inside this circle.
- A method overlaps(Circle2D circle) return true if the specified
circle overlaps with this circle.

I calculate the distance between two circles:
- double distance = Math.sqrt(Math.pow(circle.x - getX(), 2.0) +
Math.pow(circle.y - getY(), 2.0));

It's wired too me because I think it is not wrong.


// TEST CODE
public class Exercise10_11 {
	public static void main(String[] args) {
		Circle2D c1 = new Circle2D(2, 2, 5.5);
		System.out.println("Area is " + c1.getArea());
		System.out.println("Perimeter is " + c1.getPerimeter());
		System.out.println(c1.contains(3, 3));
		System.out.println(c1.contains(new Circle2D(4, 5, 10.5)));
		System.out.println(c1.overlaps(new Circle2D(3, 5, 2.3)));
	}
}

// Circle2D Class
public class Circle2D {
	private double x;
	private double y;
	private double radius;

	public Circle2D() {
		x = 0;
		y = 0;
		radius = 1;
	}

	public Circle2D(double x, double y, double radius) {
		this.x = x;
		this.y = y;
		this.radius = radius;
	}

	public double getX() {
		return x;
	}

	public double getY() {
		return y;
	}

	public double getArea() {
		return radius * radius * Math.PI;
	}

	public double getPerimeter() {
		return 2 * radius * Math.PI;
	}

	public boolean contains(double x, double y) {
		double distance = Math.pow(getX() - x, 2.0) + Math.pow(getY() - y,
2.0);
		if (distance <= radius)
			return true;
		else
			return false;
	}

	public boolean contains(Circle2D circle) {
		double distance = Math.sqrt(Math.pow(circle.x - getX(), 2.0) +
Math.pow(circle.y - getY(), 2.0));
		if (distance <= Math.abs(radius - circle.radius))
			return true;
		else
			return false;

	}

	public boolean overlaps(Circle2D circle) {
		double distance = Math.sqrt(Math.pow(circle.x - getX(), 2.0) +
Math.pow(circle.y - getY(), 2.0));
		if (distance > Math.abs(radius - circle.radius) && distance <
Math.abs(radius + circle.radius))
			return true;
		else
			return false;
	}
}

[toc] | [next] | [standalone]


#3318

Frombyhesed <byhesed@gmail.com>
Date2011-04-30 01:59 -0700
Message-ID<14270bba-4ef7-4144-bba3-e0a1bb943fca@a21g2000prj.googlegroups.com>
In reply to#3317
On Apr 30, 5:33 pm, byhesed <byhe...@gmail.com> wrote:
> What's wrong with contains and overlaps method in Circle2D class?
> It returns incorrect answers.
>
> - A method contains(double x, double y) returns true if the specified
> point(x,y) is inside this circle.
> - A method contains(Circle2D circle) returns true if the specified
> circle is inside this circle.
> - A method overlaps(Circle2D circle) return true if the specified
> circle overlaps with this circle.
>
> I calculate the distance between two circles:
> - double distance = Math.sqrt(Math.pow(circle.x - getX(), 2.0) +
> Math.pow(circle.y - getY(), 2.0));
>
> It's wired too me because I think it is not wrong.
>
> // TEST CODE
> public class Exercise10_11 {
>         public static void main(String[] args) {
>                 Circle2D c1 = new Circle2D(2, 2, 5.5);
>                 System.out.println("Area is " + c1.getArea());
>                 System.out.println("Perimeter is " + c1.getPerimeter());
>                 System.out.println(c1.contains(3, 3));
>                 System.out.println(c1.contains(new Circle2D(4, 5, 10.5)));
>                 System.out.println(c1.overlaps(new Circle2D(3, 5, 2.3)));
>         }
>
> }
>
> // Circle2D Class
> public class Circle2D {
>         private double x;
>         private double y;
>         private double radius;
>
>         public Circle2D() {
>                 x = 0;
>                 y = 0;
>                 radius = 1;
>         }
>
>         public Circle2D(double x, double y, double radius) {
>                 this.x = x;
>                 this.y = y;
>                 this.radius = radius;
>         }
>
>         public double getX() {
>                 return x;
>         }
>
>         public double getY() {
>                 return y;
>         }
>
>         public double getArea() {
>                 return radius * radius * Math.PI;
>         }
>
>         public double getPerimeter() {
>                 return 2 * radius * Math.PI;
>         }
>
>         public boolean contains(double x, double y) {
>                 double distance = Math.pow(getX() - x, 2.0) + Math.pow(getY() - y,
> 2.0);
>                 if (distance <= radius)
>                         return true;
>                 else
>                         return false;
>         }
>
>         public boolean contains(Circle2D circle) {
>                 double distance = Math.sqrt(Math.pow(circle.x - getX(), 2.0) +
> Math.pow(circle.y - getY(), 2.0));
>                 if (distance <= Math.abs(radius - circle.radius))
>                         return true;
>                 else
>                         return false;
>
>         }
>
>         public boolean overlaps(Circle2D circle) {
>                 double distance = Math.sqrt(Math.pow(circle.x - getX(), 2.0) +
> Math.pow(circle.y - getY(), 2.0));
>                 if (distance > Math.abs(radius - circle.radius) && distance <
> Math.abs(radius + circle.radius))
>                         return true;
>                 else
>                         return false;
>         }
>
>
>
>
>
>
>
> }

Sorry, I found answers. Formulas were wrong. :)

[toc] | [prev] | [next] | [standalone]


#3323

From"Gavino" <invalid@invalid.invalid>
Date2011-04-30 17:51 +0200
Message-ID<922ph0Fa0tU2@mid.individual.net>
In reply to#3318
"byhesed" <byhesed@gmail.com> wrote in message
news:2bc6aa50-5730-4057-b016-3a2b7154f0e9@f15g2000pro.googlegroups.com...
> Here is the correct answer.
>
> public boolean contains(Circle2D circle) {
> double distance = Math.pow(circle.x - getX(), 2.0) +
> Math.pow(circle.y - getY(), 2.0);
> if (distance <= (Math.pow(radius, 2.0) - Math.pow(circle.radius,
> 2.0)))
> return true;
> else
> return false;
>
> }
>
> public boolean overlaps(Circle2D circle) {
> double distance = Math.pow(circle.x - getX(), 2.0) +
> Math.pow(circle.y - getY(), 2.0);
> if (distance < Math.abs(Math.pow(radius, 2.0) -
> Math.pow(circle.radius, 2.0)))
> return true;
>
> else
> return false;
> }

That's still wrong.
'contains' should have
return Math.sqrt(distance) <= radius-circle.radius;
and 'overlaps' should have
return Math.sqrt(distance) <= radius+circle.radius;
as can easily be seen by drawing a simple picture.

Here I have retained your name 'distance' for what is actually the square of
the distance.

[toc] | [prev] | [next] | [standalone]


#3378

Frombyhesed <byhesed@gmail.com>
Date2011-04-30 09:01 -0700
Message-ID<7e45f31e-09cc-4bd8-90d1-aa76782bf9a5@d26g2000prn.googlegroups.com>
In reply to#3323
On 5월1일, 오전12시51분, "Gavino" <inva...@invalid.invalid> wrote:
> "byhesed" <byhe...@gmail.com> wrote in message
>
> news:2bc6aa50-5730-4057-b016-3a2b7154f0e9@f15g2000pro.googlegroups.com...
>
>
>
>
>
>
>
>
>
> > Here is the correct answer.
>
> > public boolean contains(Circle2D circle) {
> > double distance = Math.pow(circle.x - getX(), 2.0) +
> > Math.pow(circle.y - getY(), 2.0);
> > if (distance <= (Math.pow(radius, 2.0) - Math.pow(circle.radius,
> > 2.0)))
> > return true;
> > else
> > return false;
>
> > }
>
> > public boolean overlaps(Circle2D circle) {
> > double distance = Math.pow(circle.x - getX(), 2.0) +
> > Math.pow(circle.y - getY(), 2.0);
> > if (distance < Math.abs(Math.pow(radius, 2.0) -
> > Math.pow(circle.radius, 2.0)))
> > return true;
>
> > else
> > return false;
> > }
>
> That's still wrong.
> 'contains' should have
> return Math.sqrt(distance) <= radius-circle.radius;
> and 'overlaps' should have
> return Math.sqrt(distance) <= radius+circle.radius;
> as can easily be seen by drawing a simple picture.
>
> Here I have retained your name 'distance' for what is actually the square of
> the distance.

No, it's totally correct.

In the source code, distance means the distance between center of two
circles.
So, distance = Math.sqrt((x0-x1)^2 + (y0-y1)^2)

Here is conditions for determining positions of two circles.

Contains: d <= |r1 - r2|
Overlaps: |r1 - r2| < d < r1 + r2

Remember, circle is shown as x^2 + y^2 = r^2.

[toc] | [prev] | [next] | [standalone]


#3381

From"Gavino" <invalid@invalid.invalid>
Date2011-04-30 18:33 +0200
Message-ID<922rujFrlgU1@mid.individual.net>
In reply to#3378
"byhesed" <byhesed@gmail.com> wrote in message
news:7e45f31e-09cc-4bd8-90d1-aa76782bf9a5@d26g2000prn.googlegroups.com...

>No, it's totally correct.

>In the source code, distance means the distance between center of two
>circles.
>So, distance = Math.sqrt((x0-x1)^2 + (y0-y1)^2)

Yes, but in that version of your code you didn't have the sqrt.

>Here is conditions for determining positions of two circles.
>Contains: d <= |r1 - r2|
>Overlaps: |r1 - r2| < d < r1 + r2

So you are defining c1.contains(c2) to include the case where c1 is inside
c2?
That's a strange definition of containment.

Conversely, your definition of 'overlaps' gives false when one circle is
inside the other, which I would expect to count as overlapping.

Still, it's your function and you can define it how you like (but if you are
producing this for someone else, you'd better be sure the definition matches
what is expected).

[toc] | [prev] | [next] | [standalone]


#3375

Frombyhesed <byhesed@gmail.com>
Date2011-04-30 02:03 -0700
Message-ID<2bc6aa50-5730-4057-b016-3a2b7154f0e9@f15g2000pro.googlegroups.com>
In reply to#3318
Here is the correct answer.


public class Circle2D {
	private double x;
	private double y;
	private double radius;

	public Circle2D() {
		x = 0;
		y = 0;
		radius = 1;
	}

	public Circle2D(double x, double y, double radius) {
		this.x = x;
		this.y = y;
		this.radius = radius;
	}

	public double getX() {
		return x;
	}

	public double getY() {
		return y;
	}

	public double getArea() {
		return radius * radius * Math.PI;
	}

	public double getPerimeter() {
		return 2 * radius * Math.PI;
	}

	public boolean contains(double x, double y) {
		double distance = Math.pow(getX() - x, 2.0) + Math.pow(getY() - y,
2.0);
		if (distance <= Math.pow(radius, 2.0))
			return true;
		else
			return false;
	}

	public boolean contains(Circle2D circle) {
		double distance = Math.pow(circle.x - getX(), 2.0) +
Math.pow(circle.y - getY(), 2.0);
		if (distance <= (Math.pow(radius, 2.0) - Math.pow(circle.radius,
2.0)))
			return true;
		else
			return false;

	}

	public boolean overlaps(Circle2D circle) {
		double distance = Math.pow(circle.x - getX(), 2.0) +
Math.pow(circle.y - getY(), 2.0);
		if (distance < Math.abs(Math.pow(radius, 2.0) -
Math.pow(circle.radius, 2.0)))
			return true;

		else
			return false;
	}
}

[toc] | [prev] | [next] | [standalone]


#3319

Frombyhesed <byhesed@gmail.com>
Date2011-04-30 02:50 -0700
Message-ID<511ca68f-7866-4658-9b2b-b1c0c013a030@a21g2000prj.googlegroups.com>
In reply to#3317
On 4월30일, 오후6시08분, Patricia Shanahan <p...@acm.org> wrote:
> On 4/30/2011 1:33 AM, byhesed wrote:
> ...> - double distance = Math.sqrt(Math.pow(circle.x - getX(), 2.0) +
> > Math.pow(circle.y - getY(), 2.0));
> ...
> >    public boolean contains(double x, double y) {
> >            double distance = Math.pow(getX() - x, 2.0) + Math.pow(getY() - y,
> > 2.0);
> >            if (distance<= radius)
> >                    return true;
> >            else
> >                    return false;
> >    }
>
> ...
>
> I suggest comparing the distance calculation you actually use in the
> contains(double x, double y) method to the distance calculation you
> described.
>
> If you have a calculation you need to do a lot, why not write and test a
> separate method to do it, rather than writing the calculation in-line
> repeatedly?
>
> What is the contains(Circle2D circle) method supposed to return if
> circle contains this?
> Patricia

I know the source code I had posted is silly.
I do not perform any optimization because it is just an example.
It is an exercise from a Java book, Introduction to Java Programming 8/
e.
The reason I don't add a separate method is the author suggests not
adding any other data fields and methods.

Anyway, thank you for your advice.

[toc] | [prev] | [next] | [standalone]


#3320

Frombyhesed <byhesed@gmail.com>
Date2011-04-30 08:42 -0700
Message-ID<1598343d-42e2-4a65-9677-20c12675b174@n2g2000prj.googlegroups.com>
In reply to#3319
On 4월30일, 오후6시50분, byhesed <byhe...@gmail.com> wrote:
> On 4월30일, 오후6시08분, Patricia Shanahan <p...@acm.org> wrote:
>
>
>
>
>
>
>
>
>
> > On 4/30/2011 1:33 AM, byhesed wrote:
> > ...> - double distance = Math.sqrt(Math.pow(circle.x - getX(), 2.0) +
> > > Math.pow(circle.y - getY(), 2.0));
> > ...
> > >    public boolean contains(double x, double y) {
> > >            double distance = Math.pow(getX() - x, 2.0) + Math.pow(getY() - y,
> > > 2.0);
> > >            if (distance<= radius)
> > >                    return true;
> > >            else
> > >                    return false;
> > >    }
>
> > ...
>
> > I suggest comparing the distance calculation you actually use in the
> > contains(double x, double y) method to the distance calculation you
> > described.
>
> > If you have a calculation you need to do a lot, why not write and test a
> > separate method to do it, rather than writing the calculation in-line
> > repeatedly?
>
> > What is the contains(Circle2D circle) method supposed to return if
> > circle contains this?
> > Patricia
>
> I know the source code I had posted is silly.
> I do not perform any optimization because it is just an example.
> It is an exercise from a Java book, Introduction to Java Programming 8/
> e.
> The reason I don't add a separate method is the author suggests not
> adding any other data fields and methods.
>
> Anyway, thank you for your advice.

Sorry, there were errors in my source code in determining the position
of two circles.

	public boolean contains(double x, double y) {
		double distance = Math.sqrt(Math.pow(getX() - x, 2.0) +
Math.pow(getY() - y, 2.0));
		if (distance <= Math.sqrt(radius))
			return true;
		else
			return false;
	}

	public boolean contains(Circle2D circle) {
		double distance = Math.sqrt(Math.pow(getX() - circle.getX(), 2.0) +
Math.pow(getY() - circle.getY(), 2.0));
		if (distance <= Math.abs(Math.sqrt(radius) -
Math.sqrt(circle.radius)))
			return true;
		else
			return false;

	}

	public boolean overlaps(Circle2D circle) {
		double distance = Math.sqrt(Math.pow(getX() - circle.getX(), 2.0) +
Math.pow(getY() - circle.getY(), 2.0));
		if (Math.abs(Math.sqrt(radius) - Math.sqrt(circle.radius)) <
distance && distance < Math.abs(Math.sqrt(radius) +
Math.sqrt(circle.radius)))
			return true;
		else
			return false;
	}

[toc] | [prev] | [next] | [standalone]


#3377

From"Gavino" <invalid@invalid.invalid>
Date2011-04-30 17:59 +0200
Message-ID<922pulFd6lU1@mid.individual.net>
In reply to#3320
"byhesed" <byhesed@gmail.com> wrote in message
news:1598343d-42e2-4a65-9677-20c12675b174@n2g2000prj.googlegroups.com...

>Sorry, there were errors in my source code in determining the position
>of two circles.

>public boolean contains(double x, double y) {
>double distance = Math.sqrt(Math.pow(getX() - x, 2.0) +
>Math.pow(getY() - y, 2.0));
>if (distance <= Math.sqrt(radius))

You're going backwards.
This should be
if (distance <= radius)

The others are still wrong too - see my previous post.

[toc] | [prev] | [next] | [standalone]


#3388

From"John B. Matthews" <nospam@nospam.invalid>
Date2011-04-30 17:25 -0400
Message-ID<nospam-36D66E.17252830042011@news.aioe.org>
In reply to#3319
In article 
<511ca68f-7866-4658-9b2b-b1c0c013a030@a21g2000prj.googlegroups.com>,
 byhesed <byhesed@gmail.com> wrote:

> On 4ø˜30¿¦, ø¿»Ÿ6‡ˆ08†­, Patricia Shanahan <p...@acm.org> wrote:
> > [...]
> >
> > If you have a calculation you need to do a lot, why not write and 
> > test a separate method to do it, rather than writing the 
> > calculation in-line repeatedly?
> >
> > [...]
> 
> I know the source code I had posted is silly.
> I do not perform any optimization because it is just an example.

I would argue that the re-factoring suggested by Patricia is an 
opportunity to reduce error, both now and in future development or 
maintenance. I know it's tempting to dismiss the work as temporary, but 
we've all seen a prototype sneak into production.

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

[toc] | [prev] | [next] | [standalone]


#3392

FromPatricia Shanahan <pats@acm.org>
Date2011-04-30 17:03 -0700
Message-ID<qIidnUiax7X4PiHQnZ2dnUVZ_sWdnZ2d@earthlink.com>
In reply to#3388
On 4/30/2011 2:25 PM, John B. Matthews wrote:
> In article
> <511ca68f-7866-4658-9b2b-b1c0c013a030@a21g2000prj.googlegroups.com>,
>   byhesed<byhesed@gmail.com>  wrote:
>
>> On 4ø˜30¿¦, ø¿»Ÿ6‡ˆ08†­, Patricia Shanahan<p...@acm.org>  wrote:
>>> [...]
>>>
>>> If you have a calculation you need to do a lot, why not write and
>>> test a separate method to do it, rather than writing the
>>> calculation in-line repeatedly?
>>>
>>> [...]
>>
>> I know the source code I had posted is silly.
>> I do not perform any optimization because it is just an example.
>
> I would argue that the re-factoring suggested by Patricia is an
> opportunity to reduce error, both now and in future development or
> maintenance. I know it's tempting to dismiss the work as temporary, but
> we've all seen a prototype sneak into production.
>

I certainly proposed it as a means to the achieving correct code.

Not taking the square root, and doing some comparisons between squares
of distances, is a performance optimization that may or may not be
useful, depending on how often the code is run. It is premature
optimization, and a very bad idea, until the code is running correctly.

Patricia

[toc] | [prev] | [next] | [standalone]


#3410

From"John B. Matthews" <nospam@nospam.invalid>
Date2011-05-01 03:10 -0400
Message-ID<nospam-B1E226.03102401052011@news.aioe.org>
In reply to#3392
In article <qIidnUiax7X4PiHQnZ2dnUVZ_sWdnZ2d@earthlink.com>,
 Patricia Shanahan <pats@acm.org> wrote:

> On 4/30/2011 2:25 PM, John B. Matthews wrote:
> > In article
> > <511ca68f-7866-4658-9b2b-b1c0c013a030@a21g2000prj.googlegroups.com>,
> >   byhesed<byhesed@gmail.com>  wrote:
> >
> >> On 4ø˜30¿|, ø¿»Ÿ6‡ˆ08†-, Patricia Shanahan<p...@acm.org>  wrote:
> >>> [...]
> >>>
> >>> If you have a calculation you need to do a lot, why not write and
> >>> test a separate method to do it, rather than writing the
> >>> calculation in-line repeatedly?
> >>>
> >>> [...]
> >>
> >> I know the source code I had posted is silly.
> >> I do not perform any optimization because it is just an example.
> >
> > I would argue that the re-factoring suggested by Patricia is an
> > opportunity to reduce error, both now and in future development or
> > maintenance. I know it's tempting to dismiss the work as temporary, but
> > we've all seen a prototype sneak into production.
> >
> 
> I certainly proposed it as a means to the achieving correct code.
> 
> Not taking the square root, and doing some comparisons between squares
> of distances, is a performance optimization that may or may not be
> useful, depending on how often the code is run. It is premature
> optimization, and a very bad idea, until the code is running correctly.

I see what you mean, now. I had thought some re-factoring would lend 
clarity, but I over-estimated the benefit.

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

[toc] | [prev] | [next] | [standalone]


#3376

FromPatricia Shanahan <pats@acm.org>
Date2011-04-30 02:08 -0700
Message-ID<ZbSdnTVJKocTTCbQnZ2dnUVZ_hCdnZ2d@earthlink.com>
In reply to#3317
On 4/30/2011 1:33 AM, byhesed wrote:
...
> - double distance = Math.sqrt(Math.pow(circle.x - getX(), 2.0) +
> Math.pow(circle.y - getY(), 2.0));
...
> 	public boolean contains(double x, double y) {
> 		double distance = Math.pow(getX() - x, 2.0) + Math.pow(getY() - y,
> 2.0);
> 		if (distance<= radius)
> 			return true;
> 		else
> 			return false;
> 	}
...

I suggest comparing the distance calculation you actually use in the
contains(double x, double y) method to the distance calculation you
described.

If you have a calculation you need to do a lot, why not write and test a
separate method to do it, rather than writing the calculation in-line
repeatedly?

What is the contains(Circle2D circle) method supposed to return if
circle contains this?

Patricia

[toc] | [prev] | [next] | [standalone]


#3382

FromRoedy Green <see_website@mindprod.com.invalid>
Date2011-04-30 11:49 -0700
Message-ID<08mor6d59rnoq6hhd8s4q6lgpn8nrioovg@4ax.com>
In reply to#3317
On Sat, 30 Apr 2011 01:33:34 -0700 (PDT), byhesed <byhesed@gmail.com>
wrote, quoted or indirectly quoted someone who said :

>What's wrong with contains and overlaps method in Circle2D class?
>It returns incorrect answers.

Usually inside/outside weirdness is caused by winding direction.  A
shape defined clockwise is not the same as a shape defined
anti-clockwise.

Whenever you define a shape, you really define two, the obvious one,
and the one containing everything but the obvious one.

It might help to draw some shapes and fill them with colours to make
sure you have them defined properly.
-- 
Roedy Green Canadian Mind Products
http://mindprod.com
Politicians complain that Kindles and iBooks are killing jobs by 
destroying the paper book industry.  I see it that they have create a way 
to produce books for less than a third the cost without destroying forests 
and emitting greenhouse gases in the process.  They have created wealth.  
They are encouraging literacy and cutting the costs of education.  

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web