POJ1329 Circle Through Three Points(三角形外接圆)

题目链接:

  http://poj.org/problem?id=1329

题目描述:

Circle Through Three Points

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

题目大意:

  给三个点求出三角形外接圆

  并输出圆的标准型和一般型

思路:

  套模板

  注意输出处理数值为0(输出x^2)

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <cmath>
 6 #include <vector>
 7 using namespace std;
 8
 9 const double EPS = 1e-10;        //精度系数
10 const double PI = acos(-1.0);    //π
11
12
13 struct Point {
14     double x, y;
15     Point(double x = 0, double y = 0) :x(x), y(y) {}
16 };    //点的定义
17
18 typedef Point Vector;    //向量的定义
19
20 Vector operator - (Vector A, Vector B) { return Vector(A.x - B.x, A.y - B.y); }    //向量减法
21
22 int dcmp(double x) {
23     if (fabs(x) < EPS)return 0; else return x < 0 ? -1 : 1;
24 }    //与0的关系
25
26 double Dot(Vector A, Vector B) { return A.x*B.x + A.y*B.y; }    //向量点乘
27 double Length(Vector A) { return sqrt(Dot(A, A)); }    //向量长度
28
29 struct Circle {
30     Point c;
31     double r;
32     Circle() :c(Point(0, 0)), r(0) {}
33     Circle(Point c, double r = 0) :c(c), r(r) {}
34     Point point(double a) { return Point(c.x + cos(a)*r, c.y + sin(a)*r); }    //输入极角返回点坐标
35 };    //圆
36
37 Circle CircumscribedCircle(Point p1, Point p2, Point p3) {
38     double Bx = p2.x - p1.x, By = p2.y - p1.y;
39     double Cx = p3.x - p1.x, Cy = p3.y - p1.y;
40     double D = 2 * (Bx*Cy - By*Cx);
41     double cx = (Cy*(Bx*Bx + By*By) - By*(Cx*Cx + Cy*Cy)) / D + p1.x;
42     double cy = (Bx*(Cx*Cx + Cy*Cy) - Cx*(Bx*Bx + By*By)) / D + p1.y;
43     Point p = Point(cx, cy);
44     return Circle(p, Length(p1 - p));
45 }    //三角形外接圆
46
47 Point A, B, C;
48
49 void print(double num) {
50     if (dcmp(num) < 0) { printf("- "); num = -num; } else printf("+ ");
51     printf("%.3lf", num);
52 }    //输出
53
54 int main() {
55     while (~scanf("%lf%lf%lf%lf%lf%lf", &A.x, &A.y, &B.x, &B.y, &C.x, &C.y)) {
56         Circle ans = CircumscribedCircle(A, B, C);
57         double a = ans.c.x, b = ans.c.y;
58         double c = -2 * a, d = -2 * b, e = a*a + b*b - ans.r*ans.r;
59         int tmp = dcmp(a);
60         if (tmp == 0)printf("x^2");
61         else { printf("(x "); print(-a); printf(")^2"); }
62         printf(" + ");
63         tmp = dcmp(b);
64         if (tmp == 0)printf("y^2");
65         else { printf("(y "); print(-b); printf(")^2"); }
66         printf(" = %.3lf^2\n", ans.r);
67         printf("x^2 + y^2 "); print(c); printf("x "); print(d); printf("y "); print(e);
68         printf(" = 0\n\n");
69     }
70 }
时间: 2024-08-12 19:24:25

POJ1329 Circle Through Three Points(三角形外接圆)的相关文章

poj1329Circle Through Three Points(三角形外接圆)

链接 套模板 不知道有没有x,y=0情况,不过这种情况都按+号输出的. 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vector> 7 #include<cmath> 8 #include<queue> 9 #include&l

POJ 1329 Circle Through Three Points(求三角形的外接圆)

Circle Through Three Points 博客原文地址:http://blog.csdn.net/xuechelingxiao/article/details/40985403 题目大意: 给你三个不共线的三个点的坐标,求出过这三个点的圆的方程.写出方程的两种形式. 解题思路: 其实题目要求写出的方程的形式中包含圆心坐标跟半径,所以说关键问题其实就是求出过三点圆的圆心跟半径就OK了. 其实就是个求三角形外接圆的题目,最后加上一些蛋疼的输出控制就可以了. 代码写的有点麻烦,看到Dis

poj1266Cover an Arc(三角形外接圆)

链接 求出三角形的外接圆,通过圆心和半径可以知道这个圆的上下左右最远点,分别判断这个四个点跟弧的两端点A,B的关系,假如判断P点,弧内给出点为C,判断PC是否与AB相交即可判断出P是否在弧上. 精度问题 ceil-eps floor+eps 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h>

POJ 1329 Circle Through Three Points

Circle Through Three Points Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3678   Accepted: 1542 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

HDOJ 4720 Naive and Silly Muggles 三角形外接圆

当是钝角三角形时,就是最长边为直径的圆最小. 否则,求三角形的外接圆 Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 700    Accepted Submission(s): 451 Problem Description Three wizards are doing a exper

hdu 1374 求三角形外接圆的半径

两种求三角形外接圆半径的方法: 方法一: 已知三角形的三边为a,b,c,a小于等于b小于等于c, 它的外接圆半径为 R=abc/( 4S) S为三角形面积,可由海伦公式得到:S=√[p(p-a)(p-b)(p-c)]其中P是周长的一半 证明:对于任意三角形,其面积S=(1/2)*absinC 由正弦定理:a/sinA=b/sinB=c/sinC=2R 因,c/sinC=2R 故,R=c/2sinC 又由面积公式得:sinC=2S/ab 故,R=(c/2)/(2S/ab) 即,R=abc/4S 方

POJ1329题

Circle Through Three Points Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) Total Submission(s) : 35   Accepted Submission(s) : 8 Problem Description Your team is to write a program that, given the Cartesian coordinat

Acdream 1203 KIDx&#39;s Triangle(解三角形)

题目链接:传送门 分析 给定角a,b,c,d.然后求角AED,这题其实就是高中的计算几何解三角形题目. 正弦定理: A/sin(A) = B/sin(B) = C/sin(C)=2*R (R为三角形外接圆的半径) 余弦定理:A^2 = B^2 + C^2 - 2*B*C*cos(A). 然后我们设AB = x ,然后可以通过正弦定理求出AD,BD,BE,AE,然后通过余弦定理 可以求出DE最后在通过正弦定理就可以求出角AED.需要注意的是asin()的范围为 [-pi/2,pi/2],我们得到的

Voronoi图和Delaunay三角形和凸包

写一下最近写的一点东西... 最近在上算法课,上课老师讲到了维诺图,自己觉得很有意思就研究了一下,并用java写了一个简单的se程序用来显示维诺图和Delaunay三角形还有凸包. 首先介绍一下凸包,凸包在数学里是很常见的,给定一些点,然后找出包含这些的最小凸包,一般是这么做的.至于凸包的定义维基百科或者百度都行,自己查一查就知道,通俗的讲就是延长每一条边,剩下的图形总在边的一边. (界面有点丑) 这边给出一下我程序运行出来的凸包 然后是Delaunay三角形,这个三角形是这样的,可以在凸包里面