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>
  6 #include<vector>
  7 #include<cmath>
  8 #include<queue>
  9 #include<set>
 10 using namespace std;
 11 #define N 100000
 12 #define LL long long
 13 #define INF 0xfffffff
 14 const double eps = 1e-8;
 15 const double pi = acos(-1.0);
 16 const double inf = ~0u>>2;
 17 struct Point
 18 {
 19     double x,y;
 20     Point(double x=0,double y=0):x(x),y(y) {}
 21 }p[4];
 22 typedef Point pointt;
 23 pointt operator + (Point a,Point b)
 24 {
 25      return Point(a.x+b.x,a.y+b.y);
 26 }
 27 pointt operator - (Point a,Point b)
 28 {
 29         return Point(a.x-b.x,a.y-b.y);
 30 }
 31 int dcmp(double x)
 32 {
 33     if(fabs(x)<eps) return 0;
 34     else return x<0?-1:1;
 35 }
 36 struct Circle
 37 {
 38     Point center;
 39     double r;
 40 };
 41 double cross(Point a,Point b)
 42 {
 43     return a.x*b.y-a.y*b.x;
 44 }
 45 double mul(Point p0,Point p1,Point p2)
 46 {
 47     return cross(p1-p0,p2-p0);
 48 }
 49 double dis(Point a)
 50 {
 51     return a.x*a.x+a.y*a.y;
 52 }
 53 double area()
 54 {
 55     return fabs(cross(p[1]-p[3],p[2]-p[3]))/2;
 56 }
 57 bool seginter(pointt a1,pointt a2,pointt b1,pointt b2)
 58 {
 59      double c1 = cross(a2-a1,b1-a1),c2 = cross(a2-a1,b2-a1),
 60             c3 = cross(b2-b1,a1-b1),c4 = cross(b2-b1,a2-b1);
 61      return dcmp(c1)*dcmp(c2)<0&&dcmp(c3)*dcmp(c4)<0;
 62 }
 63 struct Circle Circumcircle()
 64 {
 65     Circle tmp;
 66     double a,b,c,c1,c2;
 67     double xa,ya,xb,yb,xc,yc;
 68     a = sqrt(dis(p[3]-p[1]));
 69     b = sqrt(dis(p[1]-p[2]));
 70     c = sqrt(dis(p[2]-p[3]));
 71     //根据s = a*b*c/R/4,求半径
 72     tmp.r = (a*b*c)/(area()*4.0);
 73     xa = p[3].x;
 74     ya = p[3].y;
 75     xb = p[1].x;
 76     yb = p[1].y;
 77     xc = p[2].x;
 78     yc = p[2].y;
 79     c1 = (dis(p[3])-dis(p[1]))/2;
 80     c2 = (dis(p[3])-dis(p[2]))/2;
 81     tmp.center.x = (c1*(ya-yc)-c2*(ya-yb))/((xa-xb)*(ya-yc)-(xa-xc)*(ya-yb));
 82     tmp.center.y = (c1*(xa-xc)-c2*(xa-xb))/((ya-yb)*(xa-xc)-(ya-yc)*(xa-xb));
 83     return tmp;
 84 }
 85 int main()
 86 {
 87     int i;
 88     double r;
 89     int w0,w1,h0,h1;
 90     for(i = 1; i <= 3 ; i++)
 91     scanf("%lf%lf",&p[i].x,&p[i].y);
 92     Circle cc = Circumcircle();
 93     r = cc.r;
 94
 95     Point q[5];
 96     for(i = 1 ;i < 5 ;i++)
 97     q[i] = cc.center;
 98     q[1].x-=r,q[2].x+=r,q[3].y-=r,q[4].y+=r;
 99
100     if(!seginter(q[1],p[3],p[1],p[2])) w0 = floor(q[1].x+eps);
101     else w0 = floor(min(p[1].x,p[2].x)+eps);
102
103     if(!seginter(q[2],p[3],p[1],p[2]))  w1 = ceil(q[2].x-eps);
104     else w1 = ceil(max(p[1].x,p[2].x)-eps);
105
106     if(!seginter(q[3],p[3],p[1],p[2])) h0 = floor(q[3].y+eps);
107     else h0 = floor(min(p[1].y,p[2].y)+eps);
108
109     if(!seginter(q[4],p[3],p[1],p[2])) h1 = ceil(q[4].y-eps);
110     else h1 = ceil(max(p[1].y,p[2].y)-eps);
111
112     printf("%d\n",(h1-h0)*(w1-w0));
113     return 0;
114 }

poj1266Cover an Arc(三角形外接圆),布布扣,bubuko.com

时间: 2024-08-26 08:18:27

poj1266Cover an Arc(三角形外接圆)的相关文章

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 poin

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

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 方

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

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

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

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三角形,这个三角形是这样的,可以在凸包里面

POJ 2546 &amp; ZOJ 1597 Circular Area 两圆的面积交

Circular Area Time Limit: 2 Seconds      Memory Limit: 65536 KB Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three digits after decimal point. Input In the single line of in

计算几何及其应用——解析几何

写在前面:刚学专业课的时候,记得有天突发奇想,心说高三数学的压轴题能不能写个程序跑出答案,这样岂不是解放了数万苦逼高三生的双手?但是当时也仅仅是停留在想法上面,因为高中的解析几何虽然步骤程序化,但是有时候需要灵巧的因式分解,感觉以目前的编程水平还是写不出来,但是了解到数学有一个分支——计算几何,专门利用计算机来进行几何计算的一门科学,并且还与计算机图形学.计算机视觉和图像处理.机器人.计算机辅助设计和制造等高深学科有着联系(摘自<计算几何与应用>导言),所以今天怀着激动的心情开始了这个专题的学