Malfatti Circles
Time limit1sMemory limit128 MB
Given triangle vertices, compute the radii of the three classical Malfatti circles using the known closed-form formula.
- Level
Medium6 of 10
- Topics
- Math, Geometry, Implementation
- Solved
- No attempts yet
Problem
Inside a triangle you can draw three circles so that each circle is tangent to the other two circles and to two sides of the triangle. These three circles are called the Malfatti circles. Mathematicians have studied them for more than two centuries, and it has been proven that for any triangle the Malfatti circles always exist and are unique.
For example, if the three vertices of the triangle are (20, 80), (-40, -20), (120, -20), the Malfatti circles are:
- center (24.281677, 45.219486), radius 21.565935
- center (3.110950, 4.409005), radius 24.409005
- center (54.556724, 7.107493), radius 27.107493
And if the vertices are (20, -20), (120, -20), (-40, 80), the Malfatti circles are:
- center (25.629089, -10.057956), radius 9.942044
- center (53.225883, -0.849435), radius 19.150565
- center (19.701191, 19.203466), radius 19.913790
Given a triangle, write a program that computes the radii of its three Malfatti circles.
Input
The input consists of several test cases. Each test case is a single line containing six integers separated by spaces. These are the coordinates of the triangle's vertices , , , given in counterclockwise order. The input satisfies:
- Every coordinate is greater than and less than .
- No Malfatti circle has a radius smaller than .
The last line contains six zeros and must not be processed.
Output
For each test case, print the radii , , of the three Malfatti circles on one line, separated by spaces. is the radius of the circle closest to vertex . Round each radius to exactly six digits after the decimal point (rounding at the seventh decimal place).