Tangent from a point to a circle
Point , circle , .
- → no tangent ( is inside);
- → one (at itself);
- → two, and the tangent length is .
The tangent points lie on the circle centred at and on the circle with diameter — so they are a circle-circle intersection:
vector<PD> tangentPoints(PD p, PD c, double r) {
double d2 = norm2(p - c);
if (d2 < r * r - EPS) return {};
PD u = p - c;
double a = r * r / d2;
double h = r * sqrt(max(0.0, d2 - r * r)) / d2;
PD base = c + u * a;
PD perpU{-u.y * h, u.x * h};
if (h < EPS) return {base};
return {base - perpU, base + perpU};
}The tangent length is exactly , the square root of the power of the point — which is why the radical axis (equal power) is also the locus of equal tangent length.
Common tangents to two circles
| Configuration | External | Internal | Total |
|---|---|---|---|
| Separate () | 2 | 2 | 4 |
| Externally tangent | 2 | 1 | 3 |
| Intersecting | 2 | 0 | 2 |
| Internally tangent | 1 | 0 | 1 |
| One inside the other | 0 | 0 | 0 |
| Identical | — | — | infinite |
External tangents keep both circles on the same side; internal tangents separate them.
Construction
Both families follow from one idea: a tangent line at signed distance from and from . Writing the line as with :
which is a small linear system with two solutions per sign choice. Handling (parallel external tangents) as a separate case avoids a division by zero.
Tangent to a convex polygon from an external point
The two tangent vertices are where the polygon “turns away” from . With a CCW hull, each is found by binary search in : a vertex is the left tangent point iff both neighbours lie on the same side of line .
// sign-based ternary/binary search on the hull
bool isTangent(P p, const vector<P>& h, int i, int sign) {
int n = h.size();
int a = orient(p, h[i], h[(i + 1) % n]);
int b = orient(p, h[i], h[(i + n - 1) % n]);
return a * sign >= 0 && b * sign >= 0;
}Used for:
- the visible portion of a polygon from a viewpoint,
- adding a point to a hull in ,
- Chan’s algorithm, whose inner loop is exactly this binary search.
Where tangents appear
| Problem | Use |
|---|---|
| Shortest path around circular obstacles | the path is made of tangent segments and arcs |
| Belt / pulley length around circles | external tangents plus arcs |
| Visibility from a point | tangent lines bound the visible arc |
| Convex hull merging | tangent lines between two hulls |
| Rotating calipers | parallel tangent lines |
| Apollonius problems (circle tangent to three circles) | reduce with inversion |
| Light and shadow | tangent lines from a light source |
The belt problem
The length of a taut belt around two pulleys of radii with centre distance :
- crossed (figure-eight): ;
- open: with .
Deriving these from the tangent length is a good check that you have the configuration right.
See also: Circle-Circle Intersection · Convex Hull · Circle-Line Intersection