poj 1329(已知三点求外接圆方程.)

Circle Through Three Points

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 3766   Accepted: 1570

Description

Your team is to write a program that, given the Cartesian coordinates of three points on a plane, will find the equation of the circle through them all. The three points will not be on a straight line.
The solution is to be printed as an equation of the form

	(x - h)^2 + (y - k)^2 = r^2				(1)

and an equation of the form

	x^2 + y^2 + cx + dy - e = 0				(2)

Input

Each line of input to your program will contain the x and y coordinates of three points, in the order Ax, Ay, Bx, By, Cx, Cy. These coordinates will be real numbers separated from each other by one or more spaces.

Output

Your program must print the required equations on two lines using the format given in the sample below. Your computed values for h, k, r, c, d, and e in Equations 1 and 2 above are to be printed with three digits after the decimal point. Plus and minus signs in the equations should be changed as needed to avoid multiple signs before a number. Plus, minus, and equal signs must be separated from the adjacent characters by a single space on each side. No other spaces are to appear in the equations. Print a single blank line after each equation pair.

Sample Input

7.0 -5.0 -1.0 1.0 0.0 -6.0
1.0 7.0 8.0 6.0 7.0 -2.0

Sample Output

(x - 3.000)^2 + (y + 2.000)^2 = 5.000^2
x^2 + y^2 - 6.000x + 4.000y - 12.000 = 0

(x - 3.921)^2 + (y - 2.447)^2 = 5.409^2
x^2 + y^2 - 7.842x - 4.895y - 7.895 = 0

Source

恶心的输出..看了discuss才知道0.000要原样输出。。

#include<stdio.h>
#include<iostream>
#include<string.h>
#include <stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
const double pi =  3.141592653589793;
const double eps = 1e-8;
struct Point
{
    double x,y;
} p[3];
double dis(Point a,Point b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
///外接圆圆心坐标
Point waixin(Point a,Point b,Point c)
{
    Point p;
    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;
    p.x = a.x + (c1*b2 - c2*b1)/d, p.y=a.y + (a1*c2 -a2*c1)/d;
    return p;
}
char check(double x)
{
    if(x<-eps) return ‘+‘;
    return ‘-‘;
}
char check2(double x)
{
    if(x<-eps) return ‘-‘;
    return ‘+‘;
}
int main()
{

    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)
    {
        double a = dis(p[0],p[1]);
        double b = dis(p[1],p[2]);
        double c = dis(p[0],p[2]);
        double r = a*b*c/sqrt((a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c));
        Point center;
        center = waixin(p[0],p[1],p[2]);
        if(fabs(center.x)<eps) printf("x^2 + ");
        else printf("(x %c %.3lf)^2 + ",check(center.x),fabs(center.x));
        if(fabs(center.y)<eps) printf("y^2");
        else printf("(y %c %.3lf)^2",check(center.y),fabs(center.y));
        printf(" = %.3lf^2\n",r);

        printf("x^2 + y^2");
        double c1 = 2*center.x,d1=2*center.y;
        double r1 = center.x*center.x+center.y*center.y-r*r;
        printf(" %c %.3lfx %c %.3lfy %c %.3lf = 0\n\n",check(c1),fabs(c1),check(d1),fabs(d1),check2(r1),fabs(r1));
    }
    return 0;
}
时间: 2024-12-29 15:43:10

poj 1329(已知三点求外接圆方程.)的相关文章

poj 2242(已知三点求外接圆周长)

The Circumference of the Circle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8310   Accepted: 4960 Description To calculate the circumference of a circle seems to be an easy task - provided you know its diameter. But what if you don't

已知三点求圆心与半径

已知三点求圆心与半径  [email protected] http://blog.csdn.net/kezunhai 在计算机图像图形学中,经常会用到求圆心或圆半径的情况,本文介绍一种已知三个点求圆心和圆半径的方法(当然三个点不能共线,共线的三个点不能构成圆). 原理:相互连接三个点,选取其中的任意两条直线,通过对这两条直线的中心做垂线,两条垂线的交点就是圆心,以此点为圆心,以此点到任意一点的距离为半径画圆. 三个点分别计为pt1, pt2, pt3:取直线p1p2和p1p3(也可以取其他直线

Scala实现:已知三点坐标,求最短距离(如果在垂足不在线段内,最短距离为到其中一点的直线距离)

/** * 已知三点坐标,求其中一点到另两点的垂线距离 * (如果在垂足不在线段内,最短距离为到其中一点的直线距离) * Created by wzq on 17-11-2. */object Point2lineDistance { def main(args: Array[String]) { val v: Double = pointToLine(-3, 0, 3, 0, 0, 3) System.out.println(v) } def pointToLine(x1: Int, y1:

POJ 2208 已知空间四面体六条边长度,求体积

Pyramids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2718   Accepted: 886   Special Judge Description Recently in Farland, a country in Asia, a famous scientist Mr. Log Archeo has discovered ancient pyramids. But unlike those in Egyp

已知矩形面积求最小周长

Description There is a piece of paper in front of Tom, its length and width are integer. Tom knows the area of this paper, he wants to know the minimum perimeter of this paper. Input In the first line, there is an integer T indicates the number of te

poj 2002(好题 链式hash+已知正方形两点求另外两点)

Squares Time Limit: 3500MS   Memory Limit: 65536K Total Submissions: 18493   Accepted: 7124 Description A square is a 4-sided polygon whose sides have equal length and adjacent sides form 90-degree angles. It is also a polygon such that rotating abou

Luogu-P1027 Car的旅行路线 已知三点确定矩形 + 最短路

传送门:https://www.luogu.org/problemnew/show/P1027 题意: 图中有n个城市,每个城市有4个机场在矩形的四个顶点上.一个城市间的机场可以通过高铁通达,不同城市间要通过飞机.现在问从s到t城市最少需要多少的费用. 思路: 已知矩形的三个顶点,可以用勾股定理确定斜边后,利用平行四边形原理——两对对角顶点的x之和是相同的,y之和也是相同的得到第四个顶点.然后用求最短路的dji即可. #include <algorithm> #include <iter

已知段地址,求CPU寻址范围

已知段地址为0001H,仅通过变化偏移地址寻址,则CPU的寻址范围是? 物理地址 = 段地址×16 + 偏移地址 所以物理地址的范围是[16×1H+0H, 16×1H+FFFFH] 也就是[10H×1H+0H, 10H×1H+FFFFH] 所以CPU的寻址范围是[10H, 1000FH] 原文地址:https://www.cnblogs.com/buyishi/p/10591351.html

已知三个点坐标,求由这三个点构成的多边形的最大面积。

给出A(x0, y0) B(x1, y1) C(x2, y2) 1.求3边a,b,c 2. 先求外接圆半径.(一定存在) 海伦公式 + 正弦定理   得  R = a * b * c / (4 * S)   S = sqrt(q * (q - a) * (q - b) * (q -c));  q = (a + b + c) / 2; -----因为是正多边形. 那么只要求出一边与两半径围成的面积 * N 就好. 3. 余弦定理 求3个角. 求最大公约数就是  正多边形 每一份   最小的角度.