Request for Answer Clarification by
norcalcoder-ga
on
04 Dec 2005 11:40 PST
I kept finding more complicated solutions involving solving algabraic
equations for 2 circles of the same radius drawn with their centers at
the 2 points I have, so where they overlap are the possible center
points of the 2 cirles I'm looking for.
Your solution is much more elegant, one thing though is I do not have
the luxery of placing the 2 points on the y axis such that thier
midpoint cooincides with the origin of xy.
I spent a few hours on this and finally decided to post here,
unfortunately, shortly after I did, I found an answer on Dr. Math
website. He's calling it "vector theory".
Here it is:
***********************************************************
'Date: 01/24/97 at 21:15:10
'From: Sherri McClung
'Subject: Find center of circle
'
'Please help me find a formula to obtain the center coordinates of a
'circle if I know two points on the circle and its radius. (There
'should be two solutions)
'
'Thank you!
'
'
'------------------------------------------------------------------------------'
'
'Date: 01/26/97 at 16:06:22
'From: Doctor Mitteldorf
'Subject: Re: Find center of circle
'
'Dear Sherri,
'
'Whenever I 'm faced with a problem like this, I try to go back to the
'definitions and see how they help. If I'm looking for the center of a
'circle of radius r, then I'm looking for a point a distance r away.
'The distance between (x1, y1) and (x, y) is given by Pythagoras:
'
' sqrt ((x - x1) ^ 2 + (y - y1) ^ 2)
'
'Let's think of (x1, y1) and (x2, y2) as our two circle points, and let
'(x, y) be the point we're looking for. Then this is the equation that
'says the distance from the first point is r:
'
' (x-x1)^2 + (y-y1)^2 = r^2
'
'This is the equation that says the distance from the second point
'is r:
'
' (x-x2)^2 + (y-y2)^2 = r^2
'
'I wrote them with both sides squared because I thought it might be
'easier to work with the two equations if they didn't have the square
'roots in them.
'
'The next step is to combine these two equations algebraically and make
'an equation for x and an equation for y out of them. Usually, a
'surefire approach would be to solve one equation for y, and then
'substitute the expression you get wherever you see a y in the other
'equation.I 'm pretty sure that will work, but you'll be doing a lot
'of algebraic manipulation with square roots.
'
'So Here 's another idea for solving the problem. It should lead to the
'same answer and the algebra will be less tedious. This method,
'however, uses some fancy ideas from "vector theory", which are
'probably strange and unfamiliar to you.
'
'Think of the geometry. You know that for any two points there's a
'"mirror line" that goes halfway between them. Technically, the line
'consists of the locus of all points that are equidistant from your two
'circle points; you can think of the line as a mirror where each of
'your two points appears as a reflection of the other.
'
'Well, this line will help us a lot in constructing our center, because
'we know that the center is on the line AND because we can use
'Pythagoras to tell us where on the line the point is. Here's how we
'can do all that with algebra.
'
'First, find the distance between points 1 and 2. We'll call that q,
'and it's given by sqrt((x2-x1)^2 + (y2-y1)^2).
'
'Second, find the point halfway between your two points. We'll call it
'(x3, y3). x3 = (x1+x2)/2 and y3 = (y1+y2)/2.
'
'Now find the direction of the line between point 1 and point 2. That
'direction is (x1-x2, y1-y2).
'
'What we really want to know is the direction of the mirror line, which
'is perpendicular to the line between point 1 and point 2.
'
'Here 's a crucial trick: you can find the direction of a perpendicular
'to a line just by swapping x with y and changing the sign of one. In
'other words, if the direction of the joining line was (x1-x2, y1-y2)
'then the direction of the mirror line is (y1-y2,x2-x1).
'
'It will be helpful to "normalize" our direction which means to make
'the length of the line equal to 1. You do this just by dividing both
'the (y1-y2) and the (x2-x1) by q.
'
'The two circle centers will both be on the mirror line, and we can use
'geometry to find how far they are from the point (x3,y3): First
'notice that the distance from point (x3,y3) to either point 1 or point
'2 is just half of q. Then the distance to move along the mirror line
'is:
' sqrt (r ^ 2 - (q / 2) ^ 2)
'
'Move up the mirror line by adding a multiple of the direction line to
'the point (x3,y3) or move down the mirror line by subtracting the same
'multiple.
'
'One answer will be:
'
'x = x3 + sqrt(r ^ 2 - (q / 2) ^ 2) * (y1 - y2) / q
'y = y3 + sqrt(r ^ 2 - (q / 2) ^ 2) * (x2 - x1) / q
'
'The other will be:
'
'x = x3 - sqrt(r ^ 2 - (q / 2) ^ 2) * (y1 - y2) / q
'y = y3 - sqrt(r ^ 2 - (q / 2) ^ 2) * (x2 - x1) / q
'
'As I write this, I realize how complicated the ideas in vector theory
'can be, and I don't expect you'll be able to follow this. If you're
'interested enough to devote some time to it, ask a math teacher for
'help.
'
'Or make a start with it, get as far as you can, and write back to Dr
'Math if you get stuck.
'
'-Doctor Mitteldorf, The Math Forum
' Check out our web site!
***********************************************************
In our machine we know know approximately where the part is (in this
case it's a silicon wafer), so I can figure out which of the 2 circles
I need by finding the one whose center is closest to the center of the
MOTION STAGE thats moving the wafer.
Hedgie, what do you mean "For coding, you just need to know that sqrt
meand square root".
For coding I was not looking forward to coding "doing a lot of
algebraic manipulation with square roots". Which looked like the only
option up to this point.
I plugged this into the code and had no problems:
'First, find the distance between points 1 and 2. We'll call that q,
'and it's given by sqrt((x2-x1)^2 + (y2-y1)^2).
'
'Second, find the point halfway between your two points. We'll call it
'(x3, y3). x3 = (x1+x2)/2 and y3 = (y1+y2)/2.
'
'One answer will be:
'
'x = x3 + sqrt(r ^ 2 - (q / 2) ^ 2) * (y1 - y2) / q
'y = y3 + sqrt(r ^ 2 - (q / 2) ^ 2) * (x2 - x1) / q
'
'The other will be:
'
'x = x3 - sqrt(r ^ 2 - (q / 2) ^ 2) * (y1 - y2) / q
'y = y3 - sqrt(r ^ 2 - (q / 2) ^ 2) * (x2 - x1) / q
As I know that one of the 2 points I'm given will always be in the
upper left (-x,+y) quadrant and the other will always be in the upper
right (+x,+y) quadrant and the center will always be in the -y
direction relative to the 2 points I know I need the second possible
answer.
Comments appreciated.
Thanks.