Circle from two tangents and a point in p5js

Find a circle that touches two tangents and a point.


  • Express the circle C along bisector S as C.y = m * C.x + b
  • Calculate the distance from point P to circle C as r**2 == (P.x - C.x)**2 + (P.y - C.y)**2
  • Substitute C.y into distance PC.
  • Express tangent A as line a * x + b * y + c == 0
  • Calculate the distance from tangent A to circle C as r**2 = (a*C.x + b*C.y + c)**2 / (a**2+b**2)
  • Substitute C.y into distance AC.
  • Set distance AC equal to PC and simplify to a quadratic in terms of C.x
  • Solve for C.x using the quadratic formula.

The quadratic formula yields two solutions (red and blue). Interestingly, red or blue is closer to the intersect depending on which side of the tangents we are on.