Well, if your variables are:
C = (cx, cy) - Circle center
A = (x1, y1) - Tangent point 1
B = (x2, y2) - Tangent point 2
The lines from the circle center to the two points A
and B
are CA = A - C
and CB = B - C
respectively.
You know that a tangent is perpendicular to the line from the center. In 2D, to get a line perpendicular to a vector (x, y)
you just take (y, -x)
(or (-y, x)
)
So your two (parametric) tangent lines are:
L1(u) = A + u * (CA.y, -CA.x)
= (A.x + u * CA.y, A.y - u * CA.x)
L2(v) = B + v * (CB.y, -CB.x)
= (B.x + v * CB.y, B.x - v * CB.x)
Then to calculate the intersection of two lines you just need to use standard intersection tests.