Incircle of polygon tangent to a point

How can we find the largest incircle (not sure if it is still called incircle) tangent to a given point on a side of a polygon? Instead of being tangent to all sides of the polygon, it will be tangent to at least two sides.

enter image description here

Since the centre of the target circle is on the blue line (perpendicular to the polygon's side at point $P$), we can test the possible circles to find the largest one.

However, this is a trial and error approach. I look for a mathematical solution.


Express the line at $P$ perpendicular to its side as the curve $$\gamma : t \mapsto P +t\hat n$$ where $\hat n$ is the unit inward pointing normal vector to the side.

There are two ways the circle can be limited. As shown, it could be tangent to another side. But also, if that inward pointing vertex were lower, the increasing circle might run into the vertex before it became tangent to any side. So calculate:

  • For each vertex $V_i$, solve the equation $t^2 = d^2(V_i, \gamma(t))$ to find the $t$ for the circle tangent at $P$ and passing through $V_i$.
  • For each side $\overline{V_iV_{i+1}}$, assume the point of tangency is at $Q_s = (1-s)V_i + sV_{i+1}$. Find the equation of the line perpendicular to the side and passing through $Q_s$. Intersect that line with $\gamma$, and label that point $C_s$. The equation $$d^2(C_s, P) = d^2(C_s, Q_s)$$ can be solved to find $s$. If $s < 0$ or $s > 1$, no circle tangent at $P$ will also be tangent to this side. In that case, discard this side and move on. Otherwise, $t = d(C_s, P)$ gives the center of this circle on $\gamma$.

Among all the values for vertices and non-discarded sides, the smallest $t$ will be the circle you want.