Hi again,

I assumed that your question was a programming problem in my previous response. Here is Java code implementing what I said earlier:

Code:

/* standardAngle computes and returns the angle from 0 to 2*pi of the
vector from (cx,cy) to (x1,y1). However if the two points are the
same, a return of 0.
*/
private double standardAngle(double x1, double y1, double cx, double cy) {
double x, y, v, d;
x = x1 - cx;
y = y1 - cy;
d = Math.sqrt(x * x + y * y);
if (d == 0) {
return (-1);
}
v = Math.acos(x / d);
if (y < 0) {
v = 2 * Math.PI - v;
}
return (v);
}
// assuming the variables are defined:
double theta = standardAngle(mx, my, sx, sy);
it (theta != -1) {
px = sx + r * Math.cos(theta);
py = sy + r * Math.sin(theta);
}
else {
// some default action for the two points the same
}

Now as far as using the line from (sx,sy) to (mx,my) to intersect with the circle to find the desired point, yes, you can do it this way:

First handle the case where sx=mx (vertical line).

Otherwise,

Next substitute into the equation of the circle

to get the quadratic equation:

Use the quadratic formula to solve this last equation. By the nature of the problem, there will be two solutions, say x1 and x2. You can decide which is the desired value by:

if ((x1-sx)*(mx-sx) is positive)

px = x1 is the correct x value

else

px = x2 is the correct x value.

Once the correct x value is found, use the line equation to find the y value.

If you encode all of the above, you'll probably get at least as much code as what I gave at the beginning. One possible advantage of this approach is that no transcendental function calls are made. However, I have found the standardAngle function useful in other contexts.