Ultraviolet A live-4642-malfatti circles

Source: Internet
Author: User

Returns three vertices of a triangle and returns the radius of the three mutually tangent circles.


Although the white mouse said that the formula could be introduced, the formula was not so easy to push ...... I can't even see it on the left or right.

It should be a helper line or something ......

Because it is very easy, we have introduced a three-Element Equations About three radius, so let's try to search for them. We can just find a random radius to satisfy this equations,

So, what about binary search? Of course, what about the monotonicity?

We can see from the figure that, for example, we search for the radius r1 of the circle closest to the top vertex. Since R2 and R3 of the following two circles are all introduced by R1, due to the constraints of the equations, the following two circles must be tangent to the top circle, and certainly to the side of the triangle, but the two circles may not be tangent. Suppose R1 is too large, then the two circles must be separated, and the bottom edge of the two circles must be smaller. If R1 is too small, the two circles must be at the same time, and the bottom edge of the two circles must be larger. Okay, there is monotonicity. That is to say, the relationship between R1 and the bottom edge length is monotonically decreasing.

The lower bound of R1 is 0, but the upper bound cannot be too large. Because it is too large, R2 and R3 will be available. That is to say, the equations cannot use R1 to release the satisfied R2 and R3, A problem occurs when we bring it into the equations. Therefore, R1 cannot be too large. How big is it suitable? Listing equations is easy to understand.


This is the last question of the computational geometric basic part of the mouse, so this part is successfully completed. Through this part, the ability to parse ry is improved.


My code:

#include<iostream>#include<map>#include<string>#include<cstring>#include<cstdio>#include<cstdlib>#include<cmath>#include<queue>#include<vector>#include<algorithm>using namespace std;const double eps=1e-7;struct dot{double x,y;dot(){}dot(double a,double b){x=a;y=b;}dot operator -(const dot &a){return dot(x-a.x,y-a.y);}double mod(){return sqrt(pow(x,2)+pow(y,2));}double dis(const dot &a) {return sqrt(pow(x-a.x,2)+pow(y-a.y,2));}double mul(const dot &a) {return x*a.x+y*a.y;}};int main(){   bool flag;int i,j;dot a[3],c[3];double l,h,m,b[3],e[3],r[3],A,B,C;while(1){flag=1;for(i=0;i<3;i++){cin>>a[i].x>>a[i].y;if(a[i].x!=0||a[i].y!=0)flag=0;}if(flag)break;for(i=0;i<3;i++){c[0]=a[(i+1)%3]-a[i];c[1]=a[(i+2)%3]-a[i];b[i]=acos(c[0].mul(c[1])/c[0].mod()/c[1].mod())/2;}e[0]=a[0].dis(a[1]);e[1]=a[1].dis(a[2]);e[2]=a[0].dis(a[2]);l=0;h=min(e[0]*tan(b[0]),e[2]*tan(b[0]));while(h-l>eps){m=(l+h)/2;A=1/tan(b[1]);B=2*sqrt(m);C=m/tan(b[0])-e[0];r[0]=(sqrt(B*B-4*A*C)-B)/A/2;A=1/tan(b[2]);B=2*sqrt(m);C=m/tan(b[0])-e[2];r[1]=(sqrt(B*B-4*A*C)-B)/A/2;r[0]*=r[0];r[1]*=r[1];if(r[0]/tan(b[1])+r[1]/tan(b[2])+2*sqrt(r[0]*r[1])-e[1]>0)l=m;elseh=m;}printf("%.6lf %.6lf %.6lf\n",l,r[0],r[1]);}}
Original question:

Time Limit: 3.000 seconds

  • 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 to write a program to calculate the radii of the malfatti circles of the given triangles.

Figures 7 and 8: Examples of the malfatti circles (#1 and #2 ).

Input

The input is a sequence of datasets. a dataset is a line containing six IntegersX1,Y1,X2,Y2,X3 andY3 In this 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 two conditions hold.


  • All of the coordinate values are greater than-1000 and less than 1000.
  • None of the malfatti circles of the triangle has a radius less than 0.1.

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

Output

For each input dataset, three decimal fractionsR1,R2 andR3 shocould be printed in a line in this order separated by a space. The radii of the malfatti circles nearest to the vertices with the coordinates (X1,Y1 ),(X2,Y2) and (X3,Y3) shocould beR1,R2 andR3, respectively.

None of the output values may have an error greater than 0.0001. No extra Character shoshould appear in the output.

Sample Input

20 80 -40 -20 120 -20 20 -20 120 -20 -40 80 0 0 1 0 0 1 0 0 999 1 -999 1 897 -916 847 -972 890 -925 999 999 -999 -998 -998 -999 -999 -999 999 -999 0 731 -999 -999 999 -464 -464 999 979 -436 -955 -337 157 -439 0 0 0 0 0 0

Sample output

21.565935 24.409005 27.107493 9.942044 19.150565 19.913790 0.148847 0.207107 0.207107 0.125125 0.499750 0.499750 0.373458 0.383897 0.100456 0.706768 0.353509 0.353509 365.638023 365.638023 365.601038 378.524085 378.605339 378.605339 21.895803 22.052921 5.895714

Ultraviolet A live-4642-malfatti circles

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.