当前位置: 代码迷 >> 综合 >> POJ 1329 Circle Through Three Points (三角形外心)
  详细解决方案

POJ 1329 Circle Through Three Points (三角形外心)

热度:4   发布时间:2024-01-15 04:58:02.0

http://poj.org/problem?id=1329
题意:给出三个点的坐标,求经过这三个点的圆的方程的标准式及一般式。

蛮智障的一个题,输出各种空格正负号格式,三角形外心套板子就行了。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
const double eps=1e-8;
const double PI=acos(-1.0);int sgn(double x)
{
    if(fabs(x)>eps) return 0;if(x<0) return -1;if(x>0) return 1;
}
struct Point
{
    double x,y;Point(){
    }Point(double _x,double _y){
    x=_x;y=_y;}//向量减法Point operator -(const Point &b)const{
    return Point(x-b.x,y-b.y);}//向量叉积double operator ^(const Point &b)const{
    return x*b.y-y*b.x;}//向量点积double operator *(const Point &b)const{
    return x*b.x+y*b.y;}//绕原点旋转角度B(弧度制),后x,y的变化void transXY(double B){
    double tx=x,ty=y;x=tx*cos(B)-ty*sin(B);y=tx*sin(B)+ty*cos(B);}
};
double dist(Point a,Point b)
{
    return sqrt((a-b)*(a-b));
}
Point waixin(Point a,Point b,Point c)
{
    double a1=b.x-a.x,b1=b.y-a.y,c1=(a1*a1+b1*b1)/2;double a2=c.x-a.x,b2=c.y-a.y,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);
}int main()
{
    double x1,y1,x2,y2,x3,y3;while(scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3)!=EOF){
    Point p=waixin(Point(x1,y1),Point(x2,y2),Point(x3,y3));double r=dist(Point(x1,y1),p);printf("(x ");if(p.x>0) printf("- %.3lf)^2 + (y ",p.x);else printf("+ %.3lf)^2 + (y ",fabs(p.x));if(p.y>0) printf("- %.3lf)^2 = ",p.y);else printf("+ %.3lf)^2 = ",fabs(p.y));printf("%.3lf^2\n",r);printf("x^2 + y^2 ");if(p.x>0) printf("- %.3lfx ",2*p.x);else printf("+ %.3lfx ",2*fabs(p.x));if(p.y>0) printf("- %.3lfy ",2*p.y);else printf("+ %.3lfy ",2*fabs(p.y));if(p.x*p.x+p.y*p.y-r*r<0) printf("- %.3lf = 0\n\n",fabs(p.x*p.x+p.y*p.y-r*r));else printf("+ %.3lf = 0\n\n",p.x*p.x+p.y*p.y-r*r);}return 0;
}
  相关解决方案