http://www.bnuoj.com/bnuoj/problem_show.php?pid=4209
题意:如题
题解:公式直接计算,或者角平分线求交点
【code1】:
#include <iostream>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include<stdio.h> using namespace std;
//定义点
struct point
{
double x,y;
}; typedef struct point point; double fabs(double x)
{
return x<?-x:x;
}
//定义直线
struct line
{
point a,b;
};
typedef struct line line; //两点距离
double distance(point p1,point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
//两直线求交点
point intersection(line u,line v)
{
point ret=u.a;
double t=((u.a.x-v.a.x)*(v.a.y-v.b.y)-(u.a.y-v.a.y)*(v.a.x-v.b.x))
/((u.a.x-u.b.x)*(v.a.y-v.b.y)-(u.a.y-u.b.y)*(v.a.x-v.b.x));
ret.x+=(u.b.x-u.a.x)*t;
ret.y+=(u.b.y-u.a.y)*t;
return ret;
} point incenter(point a,point b,point c)
{
line u,v;
double m,n;
u.a=a;
m=atan2(b.y-a.y,b.x-a.x);
n=atan2(c.y-a.y,c.x-a.x);
u.b.x=u.a.x+cos((m+n)/);
u.b.y=u.a.y+sin((m+n)/);
v.a=b;
m=atan2(a.y-b.y,a.x-b.x);
n=atan2(c.y-b.y,c.x-b.x);
v.b.x=v.a.x+cos((m+n)/);
v.b.y=v.a.y+sin((m+n)/);
return intersection(u,v);
} int main()
{
point a,b,c;
scanf("%lf%lf",&a.x,&a.y);
scanf("%lf%lf",&b.x,&b.y);
scanf("%lf%lf",&c.x,&c.y);
point d;
d = incenter(a,b,c);
if(fabs(d.x)<1e-) d.x=;
if(fabs(d.y)<1e-) d.y=;
printf("%.2lf %.2lf\n",d.x,d.y);
return ;
}
【code2】:
#include <iostream>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include<stdio.h> //using namespace std;
//定义点
struct point
{
double x,y;
}; double distance(point p1,point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
} int main()
{
point a,b,c;
scanf("%lf%lf",&a.x,&a.y);
scanf("%lf%lf",&b.x,&b.y);
scanf("%lf%lf",&c.x,&c.y);
point d;
double ab = distance(a,b);
double bc = distance(b,c);
double ac = distance(a,c);
d.x = (a.x*bc+b.x*ac+c.x*ab)/(ab+bc+ac);
d.y = (a.y*bc+b.y*ac+c.y*ab)/(ab+bc+ac);
printf("%.2lf %.2lf\n",d.x,d.y);
return ;
}