UVALive 4642 (B) Malfatti Circles

来源:互联网 发布:广告公司p图软件 编辑:程序博客网 时间:2024/06/05 04:46

公式:https://en.wikipedia.org/wiki/Malfatti_circles?setlang=zh-cn

// s=(a+b+c)/2;// 内心r=sqrt(s*(s-a)*(s-b)*(s-c))/s;// 内心坐标(a*x1+b*x2+c*x3)/(2*s),(a*y1+b*y2+c*y3)/(2*s);// d=MA,e=MB,f=MC// r1=r/(2*(s-a))*(s+d-r-e-f)// r2=r/(2*(s-b))*(s+e-r-d-f)// r3=r/(2*(s-c))*(s+f-r-d-e)#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<complex>using namespace std;typedef complex<double> Point;typedef Point Vector ;const double eps=1e-6;int dcmp(double x){    if(fabs(x)<eps) return 0;    else return x<0?-1:1;}double Dot(Vector A,Vector B){    return real(conj(A)*B);}double Cross(Vector A,Vector B){    return imag(conj(A)*B);}Vector Rotate(Vector A,double rad){    return A*exp(Point(0,rad));}double Length(Vector A){    return sqrt(Dot(A,A));}double Length(Point A,Point B){    return Length(B-A);}int main(){    double a,b,c,d,e,f,r,r1,r2,r3,s;    Point A,B,C,M;    double x1,y1,x2,y2,x3,y3;    while(scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3))    {        if(!dcmp(x1)&&!dcmp(y1)&&!dcmp(x2)&&!dcmp(y2)&&!dcmp(x3)&&!dcmp(y3))            break;      //  printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n",x1,y1,x2,y2,x3,y3);        A=Point(x1,y1),B=Point(x2,y2),C=Point(x3,y3);        //cout<<A<<" "<<B<<" "<<C<<endl;        a=Length(B,C),b=Length(A,C),c=Length(A,B);        s=(a+b+c)/2;        //cout<<s<<endl;        r=sqrt(s*(s-a)*(s-b)*(s-c))/s;        M=Point((a*x1+b*x2+c*x3)/2/s,(a*y1+b*y2+c*y3)/2/s);        d=Length(A,M);        e=Length(B,M);        f=Length(C,M);        r1=(r/2/(s-a))*(s+d-r-e-f);        r2=(r/2/(s-b))*(s+e-r-d-f);        r3=(r/2/(s-c))*(s+f-r-d-e);        printf("%.6lf %.6lf %.6lf\n",r1,r2,r3);    }    return 0;}
原创粉丝点击