From: "Earl F. Glynn" Newsgroups: borland.public.delphi.winapi References: <3AD36D00.519ACDD@musiker.nu> Subject: Re: Circle Date: Tue, 10 Apr 2001 22:29:34 -0500 Lines: 41 Organization: efg's Computer Lab X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 65.64.124.231 Message-ID: <3ad3d0b3_2@dnews> X-Trace: dnews 986960051 65.64.124.231 (10 Apr 2001 20:34:11 -0700) Path: dnews Xref: dnews borland.public.delphi.winapi:132283 "Erik Ronström" wrote in message news:3AD36D00.519ACDD@musiker.nu... > This is probably not the most appropriate newsgroup, but anyway: Given the current newsgroup definitions, I'd say this is as good as any. > Any three points in a plane defines a circle, unless the points are not > "in a row". Does anyone know an algorithm to find the center of that > circle? It is quite easy to do by hand, but I can't figure out how to do > it in Delphi. So where are you stuck? [Sounds like a homework problem ] Have you looked at these pages? http://www.mineconveyor.com/geocex7.htm http://acm.uva.es/problemset/v1/190.html The diagram from the last URL is particular useful. So the overall algorithm is this: 1. Given points A, B, and C (not collinear) 2. Compute midpoint of AB and BC. midpoint of AB = [(AX + BX)/2, (AY+BY)/2] -- just average the x and y values for the two points. 3. Compute the slopes of the lines AB and BC using the two point formula: m = slope of AB = (BY-AY)/(BX-AX) -- you'll have a special case to deal with for a vertical line. 4. From (3) compute the slope of a perpendicular line m' = -1/m. Remember that when the product of the slopes of two lines is -1, the lines are perpendicular? 5. Using the point-slope formula, write the equations for the two perpendicular lines: y = y1 + m'(x - x1) 6. The solution of the two equations in two unknowns from (5) will give you the center of the circle, (x,y). 7. To compute the radius, find the distance from (x,y) to any of the points. Hope this gets you going. -- efg efg2@efg2.com Earl F. Glynn, Overland Park, KS USA efg's Computer Lab Mirror: http://homepages.borland.com/efg2lab/Default.htm