马尔法蒂问题~~~~~~~~~~~~~~~~~~~~~~

#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
const double eps=1e-10;
const double PI=acos(-1);

using namespace std;


struct Point{
    double x;
    double y;
    Point(double x=0,double y=0):x(x),y(y){}
    void operator<<(Point &A) {cout<<A.x<<' '<<A.y<<endl;}
};

int dcmp(double x)  {return (x>eps)-(x<-eps); }

typedef  Point  Vector;

Vector  operator +(Vector A,Vector B) { return Vector(A.x+B.x,A.y+B.y);}

Vector  operator -(Vector A,Vector B) { return Vector(A.x-B.x,A.y-B.y); }

Vector  operator *(Vector A,double p) { return Vector(A.x*p,A.y*p);  }

Vector  operator /(Vector A,double p) {return Vector(A.x/p,A.y/p);}

// ps  cout

ostream &operator<<(ostream & out,Point & P) { out<<P.x<<' '<<P.y<<endl; return out;}

bool  operator< (const Point &A,const Point &B) { return A.x<B.x||(A.x==B.x&&A.y<B.y); }

bool  operator== ( const Point &A,const Point &B) { return dcmp(A.x-B.x)==0&&dcmp(A.y-B.y)==0;}


double  Dot(Vector A,Vector B) {return A.x*B.x+A.y*B.y;}

double  Cross(Vector A,Vector B)  {return A.x*B.y-B.x*A.y; }

double  Length(Vector A)  { return sqrt(Dot(A, A));}


double  Angle(Vector A,Vector B) {return acos(Dot(A,B)/Length(A)/Length(B));}

double  Area2(Point A,Point B,Point C ) {return Cross(B-A, C-A);}

Vector Rotate(Vector A,double rad) { return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));}
Vector Normal(Vector A) {double L=Length(A);return Vector(-A.y/L,A.x/L);}

Point GetLineIntersection(Point P,Vector v,Point Q,Vector w)
{
    Vector u=P-Q;
    double t=Cross(w, u)/Cross(v,w);
    return P+v*t;
    
}

double DistanceToLine(Point P,Point A,Point B)
{
    Vector v1=P-A; Vector v2=B-A;
    return fabs(Cross(v1,v2))/Length(v2);
    
}

double DistanceToSegment(Point P,Point A,Point B)
{
    if(A==B)  return Length(P-A);
    
    Vector v1=B-A;
    Vector v2=P-A;
    Vector v3=P-B;
    
    if(dcmp(Dot(v1,v2))==-1)    return  Length(v2);
    else if(Dot(v1,v3)>0)    return Length(v3);
    
    else return DistanceToLine(P, A, B);
    
}

Point GetLineProjection(Point P,Point A,Point B)
{
    Vector v=B-A;
    Vector v1=P-A;
    double t=Dot(v,v1)/Dot(v,v);
    
    return  A+v*t;
}

bool  SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2)
{
    double c1=Cross(b1-a1, a2-a1);
    double c2=Cross(b2-a1, a2-a1);
    double c3=Cross(a1-b1, b2-b1);
    double c4=Cross(a2-b1, b2-b1);
    
    //cout<<c1<<c2<<c3<<c4<<endl;
    return dcmp(c1)*dcmp(c2)<0&&dcmp(c3)*dcmp(c4)<0 ;
    
}

bool  OnSegment(Point P,Point A,Point B)
{
    return dcmp(Cross(P-A, P-B))==0&&dcmp(Dot(P-A,P-B))<0;
}

double PolygonArea(Point *p,int n)
{
    double area=0;
    
    for(int i=1;i<n-1;i++)
    {
        area+=Cross(p[i]-p[0], p[i+1]-p[0]);
        
    }
    return area/2;
    
}

Point  read_point()
{
    Point P;
    scanf("%lf%lf",&P.x,&P.y);
    return  P;
}

Point getA(Point P,Point Q,Point R,double a,double b,double c)
{
    double r1=a*b/(a*b+1+a);
    double r2=(c*(a+1))/(1+c*(a+1));
    
    double r=(1-r1)/(1-r1-r2);
    Vector PA=(R-P)*r;
    return PA+P;
}

Point Incenter(Point A,Point B,Point C)     //求内心坐标  注意旋转角度
{
//    if(Cross(B-C,B-A)<0)
//    {
//        
//    }
    
    double ABC=Angle(A-B,C-B);
    Vector BI=Rotate(C-B, ABC/2);
    
    double ACB=Angle(A-C,B-C);
    Vector CI=Rotate(B-C, -ACB/2);
    
    Point I=GetLineIntersection(B, BI, C, CI);
    
    return I;
    
}



int main()
{
    Point A,B,C;
    Point Zero;
    while(1)
    {
        A=read_point();
        B=read_point();
        C=read_point();
        
        if(A==Zero&&B==Zero&&C==Zero)  break;
        
        double area=fabs(Cross(B-A,C-A));
        area/=2;
        
        Point I=Incenter(A,B,C);
        //cout<<I<<endl;
        
        double r=DistanceToLine(I, A, B);
        
        double IA=Length(I-A);
        double IB=Length(I-B);
        double IC=Length(I-C);
        
        double a,b,c;
        a=Length(B-C);
        b=Length(C-A);
        c=Length(A-B);
        
        
        double  p=(a+b+c)/2;
        
        double r1=r/(p-a)/2*(p-r+IA-IB-IC);
        double r2=r/(p-b)/2*(p-r+IB-IA-IC);
        double r3=r/(p-c)/2*(p-r+IC-IA-IB);

        printf("%.6lf %.6lf %.6lf\n",r1,r2,r3);
        
    }
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const double eps=1e-9;
struct Point
{
	double x,y;
	Point(double x=0,double y=0):x(x),y(y){}
	void read()
	{
		scanf("%lf%lf",&x,&y);
		return;
	}
	void print()
	{
		printf("%.6f %.6f",x,y);
	}
};
typedef Point Vector;

Vector operator + (Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}
Vector operator - (Point A,Point B){return Vector(A.x-B.x,A.y-B.y);}
Vector operator * (Vector A,double p){return Vector(A.x*p,A.y*p);}
Vector operator / (Vector A,double p){return Vector(A.x/p,A.y/p);}

int sgn(double x)
{
	if(x>-eps&&x<eps)
		return 0;
	else if(x>eps)
		return 1;
	else
		return -1;
}
bool operator <(const Point& a,const Point& b)
{
	return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
bool operator ==(const Point& a,const Point& b)
{
	return sgn(a.x-b.x)==0&&sgn(a.y-b.y)==0;
}

double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}
double Length(Vector A){return sqrt(Dot(A,A));}
double Angle(Vector A,Vector B){return acos(Dot(A,B)/Length(A)/Length(B));}
double Cross(Vector A,Vector B){return A.x*B.y-A.y*B.x;}
double Area2(Point A,Point B,Point C){return Cross(B-A,C-A);}

Vector Rotate(Vector A,double rad)
{
	return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
Vector Normal(Vector A)
{
	double L=Length(A);
	return Vector(-A.y/L,A.x/L);
}

Point GetLineIntersection(Point P,Vector v,Point Q,Vector w)
{
	Vector u=P-Q;
	double t=Cross(w,u)/Cross(v,w);
	return P+v*t;
}
double DistanceToLine(Point P,Point A,Point B)
{
	Vector v1=B-A,v2=P-A;
	return fabs(Cross(v1,v2))/Length(v1);
}
double DistanceToSegment(Point P,Point A,Point B)
{
	if(A==B)return Length(P-A);
	Vector v1=B-A,v2=P-A,v3=P-B;
	if(sgn(Dot(v1,v2))<0) 
		return Length(v2);
	else if(sgn(Dot(v1,v3))>0)
		return Length(v3);
	else
		return fabs(Cross(v1,v2))/Length(v1);
}
Point GetLineProjection(Point P,Point A,Point B)
{
	Vector v=B-A;
	return A+v*(Dot(v,P-A)/Dot(v,v));
}
bool SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2)
{
	double c1=Cross(a2-a1,b1-a1),c2=Cross(a2-a1,b2-a1),
		   c3=Cross(b2-b1,a1-b1),c4=Cross(b2-b1,a2-b1);
	return sgn(c1)*sgn(c2)<0&&sgn(c3)*sgn(c4)<0;
}
bool OnSegment(Point p,Point a1,Point a2) // p is on segment a1,a2 strictly.
{
	return sgn(Cross(a1-p,a2-p))==0&&sgn(Dot(a1-p,a2-p))<0;
}
double solve(double A,double B,double C,double r)
{
	double g=C-A*r;
	double a=B*B,b=-(2*B*g+4*r),c=g*g;
	if((-b-sqrt(b*b-4*a*c))/2/a>0)
		return (-b-sqrt(b*b-4*a*c))/2/a;
	else
		return (-b+sqrt(b*b-4*a*c))/2/a;
}
int main()
{
	Point A,B,C;
	int xa,ya,xb,yb,xc,yc;
	while(scanf("%d%d%d%d%d%d",&xa,&ya,&xb,&yb,&xc,&yc)!=EOF&&(xa||ya||xb||yb||xc||yc))
	{
		A.x=xa;A.y=ya;
		B.x=xb;B.y=yb;
		C.x=xc;C.y=yc;
		double ab=Length(A-B);
		double bc=Length(B-C);
		double ac=Length(A-C);
		double a=acos((ac*ac+ab*ab-bc*bc)/2/ac/ab);
		double b=acos((ab*ab+bc*bc-ac*ac)/2/ab/bc);
		double c=acos((ac*ac+bc*bc-ab*ab)/2/ac/bc);
		double L=0.1,R=min(ab*tan(a/2),ac*tan(a/2));
		double r2=0,r3=0;
		while(R-L>eps)
		{
			double M=(L+R)/2;
			r3=solve(1.0/tan(a/2),1.0/tan(b/2),ab,M);
			r2=solve(1.0/tan(a/2),1.0/tan(c/2),ac,M);
			if(r3/tan(b/2)+r2/tan(c/2)+2*sqrt(r2*r3)>bc)
				L=M;
			else
				R=M;
		}
		double r1=R;
		printf("%.6f %.6f %.6f\n",r1,r3,r2);
	}
	//system("pause");
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值