zoukankan      html  css  js  c++  java
  • joj 1805

    求外接圆圆心的一道题

    #include<iostream>
    #include<stdio.h>
    #include<math.h>
    using namespace std;
    struct Point{
           double x;
           double y;
    };
    Point  circle_center(Point  pt[3]) 

               double  x1,x2,x3,y1,y2,y3; 
               double  x  =  0; 
               double  y  =  0; 

               x1  =  pt[0].x; 
               x2  =  pt[1].x; 
               x3  =  pt[2].x; 
               y1  =  pt[0].y; 
               y2  =  pt[1].y; 
               y3  =  pt[2].y; 

               x=((y2-y1)*(y3*y3-y1*y1+x3*x3-x1*x1)-(y3-y1)*(y2*y2-y1*y1+x2*x2-x1*x1))/(2*(x3-x1)*(y2-y1)-2*((x2-x1)*(y3-y1)));
                y=((x2-x1)*(x3*x3-x1*x1+y3*y3-y1*y1)-(x3-x1)*(x2*x2-x1*x1+y2*y2-y1*y1))/(2*(y3-y1)*(x2-x1)-2*((y2-y1)*(x3-x1)));
               Point center;
               center.x  =  x  ; 
               center.y  =  y  ; 
               return center;
    }
    int main()
    {
        Point p[3];
        while(scanf("%lf%lf%lf%lf%lf%lf",&p[0].x,&p[0].y,&p[1].x,&p[1].y,&p[2].x,&p[2].y)!=EOF)
        {
            Point c=circle_center(p);
            double r=sqrt((p[0].x-c.x)*(p[0].x-c.x)+(p[0].y-c.y)*(p[0].y-c.y));
            printf("(x");
            if(c.x>0)
                printf(" - %.3lf",fabs(c.x));
            if(c.x<0)
                printf(" + %.3lf",fabs(c.x));
            printf(")^2 + (y");
            if(c.y>0)
                printf(" - %.3lf",fabs(c.y));
            if(c.y<0)
                printf(" + %.3lf",fabs(c.y));
            printf(")^2 = %.3lf^2\n",fabs(r));
            double p=c.x*c.x+c.y*c.y-r*r;
            double c1=2*c.x;
            double c2=2*c.y;
            printf("x^2 + y^2");
            if(c1>0)
              printf(" - %.3lfx",fabs(c1));
            if(c1<0)
              printf(" + %.3lfx",fabs(c1));
            if(c2>0)
              printf(" - %.3lfy",fabs(c2));
            if(c2<0)
              printf(" + %.3lfy",fabs(c2));
            if(p>0)
              printf(" + %.3lf",fabs(p));
            if(p<0)
              printf(" - %.3lf",fabs(p));
            printf(" = 0\n");
            printf("\n");
        }
    }

  • 相关阅读:
    idea git 操作
    1
    python 迭代器/生成器/迭代对象
    python 中的type
    systemd 配置文件
    python 中类的初始化过程
    mysql主从错误180301
    从零开始搭建k8s-20180301
    kubernetes role
    Java程序员毕业两年自述
  • 原文地址:https://www.cnblogs.com/dchipnau/p/4985961.html
Copyright © 2011-2022 走看看