计算几何(三角形外接圆) - The Circumference of the Circle - UVA 438
题意:
给 定 三 个 不 共 线 的 点 的 坐 标 , 输 出 外 接 圆 的 周 长 。 给定三个不共线的点的坐标,输出外接圆的周长。 给定三个不共线的点的坐标,输出外接圆的周长。
输入:
多 组 测 试 数 据 , 多组测试数据, 多组测试数据,
每 组 依 次 包 括 三 个 顶 点 的 横 纵 坐 标 。 每组依次包括三个顶点的横纵坐标。 每组依次包括三个顶点的横纵坐标。
输出:
一 个 浮 点 数 , 表 示 周 长 , 小 数 点 后 保 留 两 位 数 字 。 一个浮点数,表示周长,小数点后保留两位数字。 一个浮点数,表示周长,小数点后保留两位数字。
代码:
#define _CRT_SECURE_NO_WARNINGS
#include<cstring>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1.0);
struct Point
{
double x,y;
Point(double x = 0, double y = 0):x(x),y(y){}
};
Point Excenter(Point a, Point b, Point c)
{
double a1 = b.x - a.x;
double b1 = b.y - a.y;
double c1 = (a1*a1 + b1*b1)/2;
double a2 = c.x - a.x;
double b2 = c.y - a.y;
double c2 = (a2*a2 + b2*b2)/2;
double d = a1*b2 - a2*b1;
return Point(a.x + (c1*b2 - c2*b1)/d, a.y + (a1*c2 - a2*c1)/d);
}
double dis(Point a,Point b)
{
double dx=a.x-b.x, dy=a.y-b.y;
return sqrt(dx*dx+dy*dy);
}
int main()
{
Point A,B,C;
while(~scanf("%lf%lf%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y))
{
Point O=Excenter(A,B,C);
double r=dis(O,A);
printf("%.2lf\n",2.0*pi*r);
}
return 0;
}