Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Gavino" Newsgroups: comp.lang.java.programmer Subject: Re: Programming question determining two circle's relation Date: Sat, 30 Apr 2011 17:51:37 +0200 Lines: 37 Message-ID: <922ph0Fa0tU2@mid.individual.net> 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> X-Trace: individual.net hVfcrZmZ17lZhaMYW8Uk1QLR3dJCblM1Tc+SUW8bzuwtEV4Y42 Cancel-Lock: sha1:WP1WrgHUT4oHQ+pqFaGDvnRSq7c= X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3323 "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 = 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.