My math skills are faded since my school life so I can't remember how to calculate this question. If you have a polyline with lines and arcs, and if those are not tangential, I want to smooth the polyline by adding arcs between the segments. With the command Circle and option TTR it is possible to add a circle between two tangents and a radius.

Is it possible to calculate the largest possible radius with some mathematical functions? If I try a few radii the circles soon enough starts on the outside instead of the inside (see picture 1).

Also, between two arc segments, there can be a lot of tangential circles be drawn, but how to calculate the largest one (see picture 2)?

Or are there other functions in AutoCAD to smooth a polyline programmatically?