www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/26/16:07:06

From: alaric AT abwillms DOT demon DOT co DOT uk (Alaric B. Williams)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: bounding circle vs. bounding boxes
Date: Wed, 26 Feb 1997 19:04:21 GMT
Message-ID: <3314865a.3944031@news.demon.co.uk>
References: <19970226 DOT 065019 DOT 4511 DOT 1 DOT fwec AT juno DOT com>
NNTP-Posting-Host: abwillms.demon.co.uk
Lines: 70
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hello everyone. By popular demand, I'm back...



On Wed, 26 Feb 1997 11:43:30 GMT, fwec AT juno DOT com (Mark T Logan) wrote:

>How can I calculate a bounding circle?  Anyone know?

Easy peasy!

Take the arithmetic mean of the x and y values of the points to find
the centre. Then calculate distances from that centre and find the
maximum. Now you have center and radius!

If the points are in an array points[n], where n is the number, and
each element has members x and y, we could write:

int cx,cy,cr; //circle x, y, radius

cx = cy = 0;
for(int i=0;i<n;i++) {
   cx += points[i].x;
   cy += points[i].y;
}

cx /= n; cy /= n;

for(int i=0;i<n;i++) {
   int d = (points[i].x-cx)*(points[i].x-cx) +
(points[i].y-cy)*(points[i].y-cy);
   if(d>cr) cr = d;
}

cr = (int)sqrt(cr);

>Also, If I use bounding circles, I need to be able to check
>if the bounding circle is intersected or contained by two rays
>which extend from a single point at a slight angle from one another
>(I'd do some ASCII art here, but my mailer uses a proportional font).
>How can I do this? (quickly!)

Oh, my!

Erm...

convert the circle centre x,y to polar coordinates relative to the
start of the two rays, figure out how much angle the circle radius
distends from the viewpoint of the start point, and see if the
circle's center angle, plus or minus the angle the radius distends,
intersects the range of angles the rays cover. Ok?

>Much thanks and appreciation to whoever helps me out.

:-)

>-Fwec

ABW
--

"Simply drag your mother in law's cellphone number from the
Address Book to the Laser Satellite icon, and the Targeting
Wizard will locate her. Then follow the onscreen prompts for
gigawattage and dispersion pattern..."

(Windows for Early Warning and Defence User's manual P385)

Alaric B. Williams Internet : alaric AT abwillms DOT demon DOT co DOT uk
<A HREF="http://www.abwillms.demon.co.uk/">Hello :-)</A>

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019