From: "Earl F. Glynn" Newsgroups: borland.public.delphi.winapi References: <3AD36D00.519ACDD@musiker.nu> <3ad3d0b3_2@dnews> <3AD3FD31.5806F33B@musiker.nu> Subject: Re: Circle Date: Wed, 11 Apr 2001 08:58:29 -0500 Lines: 62 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: 12.75.140.58 Message-ID: <3ad46418_2@dnews> X-Trace: dnews 986997784 12.75.140.58 (11 Apr 2001 07:03:04 -0700) Path: dnews Xref: dnews borland.public.delphi.winapi:132320 "Erik Ronström" wrote in message news:3AD3FD31.5806F33B@musiker.nu... > Yes, I knew this algorithm from school, but I didn't really know how to solve the equation between the > two lines (kx+m) in code. It's easy to do by hand, though. Do you know about Kramer's rule? > > 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. The result of this is the two midpoints. Let's name the midpoint of AB to be D, and the midpoint of BC to be E. > > 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. So you have an m1 for AB and an m2 for BC. > > 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? Here you have a m1' for AB and an m2' for BC. > I've come this far. I hope I can implement step 5 - 7, because that is what I need. > > > 5. Using the point-slope formula, write the equations for the two perpendicular lines: > > y = y1 + m'(x - x1) Point D and slope m1': y = DY + m1'(x - DX) Point E and slope m2': y = EY + m2'(x - EX) DX, DY, EX, EY, m1' and m2' are just numbers at this point. You have two equations in x and y. > > 6. The solution of the two equations in two unknowns from (5) will give you the center of the > > circle, (x,y). To keep this simple, let me rename the constants: Do you know about Cramer's Rule two equations in two unknowns. It's explained here. http://www.iln.net/html_p/c/53785/53786/53801/53873/54176.asp To use Cramer's first you must rearrange your equations: m1'*x - y = m1'*DX - DY m2'x - y = m2'*EX - EY Instead of Cramer's rule, you could just take the negative of one of the equations and add it to the other equation. This would let you solve for x. Once you have x, you could solve for y using one of the original equations. An iterative solution is not necessary. Everything is well defined for a direct solution. -- efg efg2@efg2.com Earl F. Glynn, Overland Park, KS USA efg's Computer Lab: http://www.efg2.com/Lab Mirror: http://homepages.borland.com/efg2lab/Default.htm