Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

smallest distance to circumference

5 views
Skip to first unread message

HEXbutler

unread,
Oct 25, 2010, 9:58:50 PM10/25/10
to app...@support1.mathforum.org
I'm looking to create a function that takes these variables.

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

Steketee, Scott

unread,
Oct 26, 2010, 9:24:12 AM10/26/10
to app...@support1.mathforum.org
Hi,

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

0 new messages