您的位置:首页 > Web前端

HOJ 1439 The Circumference of the Circle

2012-11-28 00:06 302 查看
http://acm.hit.edu.cn/hoj/problem/view?id=1439

给出三个点坐标 计算过这三个点的圆的周长

利用a/sinA=2R和S=0.5*bcsinA计算 S可用叉乘算

#include <stdio.h>
#include <math.h>

const double pi = acos(-1);
double find_r(double x1, double y1, double x2, double y2, double x3, double y3);

int main()
{
double r, c;
double x1, y1, x2, y2, x3, y3;

while (scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3) != EOF)
{
r = find_r(x1, y1, x2, y2, x3, y3);
c =2 * pi * r;
printf("%.2lf\n", c);
}

return 0;
}

double find_r(double x1,double y1,double x2,double y2,double x3,double y3)
{
double s,r,a,b,c;

s = fabs(0.5 * ((x1-x3) * (y2-y3) - (x2-x3) * (y1-y3)));
a = sqrt(pow((x1-x2), 2) + pow((y1-y2), 2));
b = sqrt(pow((x1-x3), 2) + pow((y1-y3), 2));
c = sqrt(pow((x3-x2), 2) + pow((y3-y2), 2));
r = (a*b*c) / (4*s);
return r;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: