origin_x,origin_y,radius,point_x,point_y
and returns x,y as a set of points that exist (rounded integers) closest to the set point_x,point_y and also reside on the circumference of the circle created around the origin with the provided radius.
Here's a picture that may help you understand it. The arrows point to where the points the function should return +/- a steady hand.
http://img180.imageshack.us/img180/9028/circleshowdotheywork.jpg
First, notice that all the shortest distances on your diagram lie along extended radii of the circle. These extended radii are rays from the circle's center C through point A (your point_x, point_y).
Then, express the equation of the ray as a linear combination of the coordinates of C and the coordinates of A:
x(t) = t*x[A] + (1-t)*x[C]
y(t) = t*y[A] + (1-t)*y[C]
where t >= 0 (to make it a ray rather than a line).
Note that this form of the equations returns point C when t=0 and point A when t=1.
Now you only need to find the correct value of t to return the intersection of the ray with the circle. (This step is left as an exercise for the reader.)
However, you said "rounded integers"; when you round the calculations, the resulting point will in general be on neither the ray nor the circle. I'm not sure what the intent of the rounding is, so don't know what to say about this.
-Scott
Scott Steketee
Sketchpad Projects