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


Groups > comp.lang.java.programmer > #3320

Re: Programming question determining two circle's relation

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.21.MISMATCH!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!n2g2000prj.googlegroups.com!not-for-mail
From byhesed <byhesed@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Programming question determining two circle's relation
Date Sat, 30 Apr 2011 08:42:37 -0700 (PDT)
Organization http://groups.google.com
Lines 84
Message-ID <1598343d-42e2-4a65-9677-20c12675b174@n2g2000prj.googlegroups.com> (permalink)
References <892252a0-e31d-426b-8f47-d37c0b2ec364@17g2000prr.googlegroups.com> <ZbSdnTVJKocTTCbQnZ2dnUVZ_hCdnZ2d@earthlink.com> <511ca68f-7866-4658-9b2b-b1c0c013a030@a21g2000prj.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 1304178158 3129 127.0.0.1 (30 Apr 2011 15:42:38 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Sat, 30 Apr 2011 15:42:38 +0000 (UTC)
Complaints-To groups-abuse@google.com
Injection-Info n2g2000prj.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:3320

Show key headers only | View raw


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;
	}

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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

csiph-web