Path: csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!news.glorb.com!postnews.google.com!a21g2000prj.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 02:50:34 -0700 (PDT) Organization: http://groups.google.com Lines: 38 Message-ID: <511ca68f-7866-4658-9b2b-b1c0c013a030@a21g2000prj.googlegroups.com> References: <892252a0-e31d-426b-8f47-d37c0b2ec364@17g2000prr.googlegroups.com> 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 1304157034 16922 127.0.0.1 (30 Apr 2011 09:50:34 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 30 Apr 2011 09:50:34 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: a21g2000prj.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:3319 On 4=BF=F930=C0=CF, =BF=C0=C8=C46=BD=C308=BA=D0, Patricia Shanahan wrote: > On 4/30/2011 1:33 AM, byhesed wrote: > ...> - double distance =3D 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 =3D Math.pow(getX() - x, 2.0) + Math.pow(get= Y() - y, > > 2.0); > > if (distance<=3D 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.