Given a line with first end point P(x1,y1) another end point is unknown, intersect with a circle that located at origin with radius R at only one point(tangent) T(x2,y2). An
All you need is in dmckee's answer, but if you care for some code check this implementation using Javascript and HTML canvas.
Full example: http://jsfiddle.net/zxqCw/1/
// find tangents
dx = cx - px;
dy = cy - py;
dd = Math.sqrt(dx * dx + dy * dy);
a = Math.asin(radius / dd);
b = Math.atan2(dy, dx);
t = b - a
ta = { x:radius * Math.sin(t), y:radius * -Math.cos(t) };
t = b + a
tb = { x:radius * -Math.sin(t), y:radius * Math.cos(t) };
Use the x,y coordinates of the intersecting equations (the one of the circle and the one of the line). That's the point.
If you have only one end point from which to draw the line you'll get two different points, as there will be two different tangent lines, one up and one down.
You can find direction of vector DX if you rotate vector DO by angle alpha (angle alpha is found as asin(len(OX) / len(DO)), which is simply arcsinus of radius over hypotenuse)
You can find the length of vector DX trivially as following: sqrt(len(DO)*len(DO) - len(OX)*len(OX))
Given the direction and length of vector DX, you can find the value of point X. One approach would be to normalize DX and multiply it by the length of it.
auto dist = D.Distance(O); auto side = sqrt(dist*dist - rad*rad) auto line = Vector2D(D, O); line.Rotate(asin(rad / dist)); //get the direction line.Normalize(); //set length to 1 line*=side; //we have the direction, now get length Point2D X = D + line;
P.S. Note that there is also a second tangent, which is found by rotating DO by minus alpha