Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx01.iad01.newshosting.com!newshosting.com!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!d26g2000prn.googlegroups.com!not-for-mail From: byhesed Newsgroups: comp.lang.java.programmer Subject: Re: Programming question determining two circle's relation Date: Sat, 30 Apr 2011 09:01:42 -0700 (PDT) Organization: http://groups.google.com Lines: 61 Message-ID: <7e45f31e-09cc-4bd8-90d1-aa76782bf9a5@d26g2000prn.googlegroups.com> References: <892252a0-e31d-426b-8f47-d37c0b2ec364@17g2000prr.googlegroups.com> <14270bba-4ef7-4144-bba3-e0a1bb943fca@a21g2000prj.googlegroups.com> <2bc6aa50-5730-4057-b016-3a2b7154f0e9@f15g2000pro.googlegroups.com> <922ph0Fa0tU2@mid.individual.net> NNTP-Posting-Host: 119.202.36.92 Mime-Version: 1.0 Content-Type: text/plain; charset=EUC-KR Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1304179302 14698 127.0.0.1 (30 Apr 2011 16:01:42 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 30 Apr 2011 16:01:42 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d26g2000prn.googlegroups.com; posting-host=119.202.36.92; posting-account=v_GC8QoAAABz34PprEBWdejdnnHZvg4_ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.60 Safari/534.24,gzip(gfe) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3378 On 5=BF=F91=C0=CF, =BF=C0=C0=FC12=BD=C351=BA=D0, "Gavino" wrote: > "byhesed" wrote in message > > news:2bc6aa50-5730-4057-b016-3a2b7154f0e9@f15g2000pro.googlegroups.com... > > > > > > > > > > > Here is the correct answer. > > > public boolean contains(Circle2D circle) { > > double distance =3D Math.pow(circle.x - getX(), 2.0) + > > Math.pow(circle.y - getY(), 2.0); > > if (distance <=3D (Math.pow(radius, 2.0) - Math.pow(circle.radius, > > 2.0))) > > return true; > > else > > return false; > > > } > > > public boolean overlaps(Circle2D circle) { > > double distance =3D 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) <=3D radius-circle.radius; > and 'overlaps' should have > return Math.sqrt(distance) <=3D 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 =3D Math.sqrt((x0-x1)^2 + (y0-y1)^2) Here is conditions for determining positions of two circles. Contains: d <=3D |r1 - r2| Overlaps: |r1 - r2| < d < r1 + r2 Remember, circle is shown as x^2 + y^2 =3D r^2.