POJ 3808 Malfatti Circles (computational geometry)

Source: Internet
Author: User

Malfatti Circles
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 250 Accepted: 125 Special Judge

Description

The con?guration of three circles packed inside a triangle such that each circle was tangent to the other of the Circles and T o The edges of the triangle have been studied by many mathematicians for more than, both centuries. Existence and uniqueness of such circles for an arbitrary triangle is easy to prove. Many methods of numerical calculation or geometric construction of such circles from an arbitrarily given triangle has been En discovered. Today, such circles is called the Malfatti circles.

Figure 7 illustrates an example. The Malfatti circles of the triangle with the vertices ( -40, -20) and ( -20) is approximately
The Circle with the center (24.281677, 45.219486) and the radius 21.565935,
The Circle with the center (3.110950, 4.409005) and the radius 24.409005, and
The Circle with the center (54.556724, 7.107493) and the radius 27.107493.

Figure 8 illustrates another example. The Malfatti circles of the triangle with the vertices ( -20, -20) and ( -40, +) are approximately
The Circle with the center (25.629089, -10.057956) and the radius 9.942044,
The Circle with the center (53.225883, -0.849435) and the radius 19.150565, and
The Circle with the center (19.701191, 19.203466) and the radius 19.913790.

Your mission is-write a program to calculate the radii of the malfatti circles of the given.

Input

The input is a sequence of datasets. A DataSet is a line containing six integers x1, y1, x2, y2, X3 and Y3 in the order, separated by a space. The coordinates of the vertices of the given triangle are (x1, y1), (x2, y2) and (x3, y3), respectively. You can assume that the vertices form a triangle counterclockwise. You can also assume that the following and the conditions hold.

All of the coordinate values is greater than-1000 and less than 1000.
None of the Malfatti circles of the triangle have a radius less than 0.1.

The end of the input is indicated to a line containing six zeros separated by a space.

Output

For each input dataset, three decimal fractions R1, R2 and R3 should is printed in a line in the order separated by a spa Ce. The radii of the Malfatti circles nearest to the vertices with the coordinates (x1, y1), (x2, y2) and (x3, y3) should is R 1, R2 and R3, respectively.

None of the output values may has an error greater than 0.0001. No extra character should appear in the output.

Sample Input

20 80-40-20 120-2020-20 120-20-40 800 0 1 0 0 10 0 999 1-999 1897-916 847-972 890-925999 999-999-998-998-999 -999-999 999-999 0 731-999-999 999-464-464 999979-436-955-337 157-4390 0 0 0 0 0

Sample Output

21.565935 24.409005 27.1074939.942044 19.150565 19.9137900.148847 0.207107 0.2071070.125125 0.499750 0.4997500.373458 0.383897 0.1004560.706768 0.353509 0.353509365.638023 365.638023 365.601038378.524085 378.605339 378.60533921.895803 22.052921 5.895714


Test instructions: gives the coordinates of the three vertices of a triangle, the three inscribed circle of the triangle, 22 tangent, and the two sides of the vertex adjacent to each vertex are tangent. Ask for a radius of three inscribed circle.

Analysis: Set of formulas.

where r is the radius of the triangular inscribed circle, S is the half perimeter.

#include <cstdio> #include <cmath>using namespace std;struct point {double X, y;} A, B, C, i;double Get_dis (Point p1, point p2) {return sqrt ((p1.x-p2.x) * (p1.x-p2.x) + (P1.Y-P2.Y) * (P1.Y-P2. y));} int main () {while (~scanf ("%lf%lf%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y, &c.x, &c.y)) {i        F (a.x = = 0 && a.y = 0 && b.x = 0 && b.y = 0 && c.x = 0 && c.y = 0) break;        Double A = Get_dis (B, C);        Double b = Get_dis (A, C);        Double c = Get_dis (A, B);  Double s = (A + B + c)/2;        Half perimeter i.x = (A * a.x + b * b.x + c * c.x)/(A + B + c); I.Y = (A * a.y + b * b.y + c * c.y)/(A + B + c); Inscribed Circle Center coordinate Double r = sqrt ((s-a) * (s-b) * (S-C)/s);        Inscribed circle RADIUS Double IA = Get_dis (A, I);        Double IB = Get_dis (B, I);        Double IC = Get_dis (C, I);        Double R1 = r/(2 * (S-A)) * (S-r + ia-ib-ic); Double r2 = r/(2 * (S-b)) * (S-r + ib-ia-ic);        Double R3 = r/(2 * (S-C)) * (S-r + Ic-ia-ib);    printf ("%.6lf%.6lf%.6lf\n", R1, r2, R3); } return 0;}


For more explanations, see http://en.wikipedia.org/wiki/Malfatti_circles.

POJ 3808 Malfatti Circles (computational geometry)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.