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). Anyone know how to get the point T? Thanks in advance!
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.
Take R
as the radius of the circle and D
the distance from the external point to the center of the circle such that D > R
.
The tanget line makes and angle of \alpha
with the line connecting the external point and the center, where
\alpha = arcsin(R/D)
The line connecting the external point (P
) and the center (C
) makes an angle with the horizontal of
\beta = arctan((C_y - P_y)/(C_x - P_x))
That gives you the angle of the tangent line with the horizontal as
\theta = \beta +/- \alpha
Note the ambiguity.
The length of the tangent segment is
L = sqrt(D^2 - R^2)
which is all you need.
Another solution; less elegant than dmindreader`s, but maybe simpler to understand:
You know that the point T
is on the circle and that the line OT
is perpendicular to the line PT
that gives you
abs(O - T) = R
dotProduct(O - T, P - T) = 0
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). Anyone know how to get the point T?
Some of the other solutions seem a little like overkill. I think the simplest way is just to notice that this is a right triangle, with vertices P, T, and O (the origin). The angle PTO is the right angle, because a tangent line is always at a right angle to a radius.
You know the length of TO
because it's of length r
and has a vertex at the origin; you know OP
because you know where O
and P
is. Given two sides of a right triangle, it's easy to find the length and direction of the third side. This is homework, so I'll leave the rest as an exercise to the reader.
__...------__ T(x2, y2)
_.-'' -(+)
,-' |----
,' | ----
,' | ' ----
/ | ` ----
/ | `. ----
/ | \ ----
| | | ----
| | | ----
| | | ----
| (+)---------------------------------------------(+) P (x1,y1)
| .'
| O |
| .'
\ /
\ ,'
` /
'. ,'
'-. _,'
'-._ _,(+) T'(x3, y3)
'`--......---'
There are two possible directions for TO
, since the point T' is also a valid tangent point, so you will have two congruent triangles.
It is not obvious to me that this is homework, but I do like the intuition that a right triangle is defined. Even so, there will be some algebra with that solution.
Another approach that seems viable is to simply define the problem as the solution of two equations in two unknowns. That is, the equation of a circle, centered at (0,0), with radius R is
x^2 + y^2 = R^2
The equation of a line that passes through the point (xt,yt), with (unknown) slope S is
(y - yt) = S*(x - xt)
Solve the system of two equations for the intersection point. Depending upon the value of S, there will be zero, one or two solutions to this pair of equations. It will also turn out that there are two values of S such that the solution is unique. Solve for those two values of S that make the solution unique, then recover the intersection point (xt,yt). I won't go through the actual solution in depth in case this is homework, but that part is trivial algebra.
My point is that this algebraic approach is another way to view the solution of the computational geometry problem. It highlights an interesting point in that there are two lines which intersect the circle at a tangent point, and that when a line intersects at a tangent point, there is a single point of intersection.
A flaw of this approach is that is fails due to a singularity for SOME problems. I.e., when the line with slope S is vertical, then S is undefined. Other approaches that rely on simple distances and the Pythagorean theorem are robust to that event.
What if we don't know the radius and tangent point coordinates...how can we calculate the radius?