poj1266Cover an Arc(三角形外接圆)
2014-07-03 15:24
211 查看
链接
求出三角形的外接圆,通过圆心和半径可以知道这个圆的上下左右最远点,分别判断这个四个点跟弧的两端点A,B的关系,假如判断P点,弧内给出点为C,判断PC是否与AB相交即可判断出P是否在弧上。
精度问题 ceil-eps floor+eps
View Code
求出三角形的外接圆,通过圆心和半径可以知道这个圆的上下左右最远点,分别判断这个四个点跟弧的两端点A,B的关系,假如判断P点,弧内给出点为C,判断PC是否与AB相交即可判断出P是否在弧上。
精度问题 ceil-eps floor+eps
#include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<stdlib.h> #include<vector> #include<cmath> #include<queue> #include<set> using namespace std; #define N 100000 #define LL long long #define INF 0xfffffff const double eps = 1e-8; const double pi = acos(-1.0); const double inf = ~0u>>2; struct Point { double x,y; Point(double x=0,double y=0):x(x),y(y) {} }p[4]; typedef Point pointt; pointt operator + (Point a,Point b) { return Point(a.x+b.x,a.y+b.y); } pointt operator - (Point a,Point b) { return Point(a.x-b.x,a.y-b.y); } int dcmp(double x) { if(fabs(x)<eps) return 0; else return x<0?-1:1; } struct Circle { Point center; double r; }; double cross(Point a,Point b) { return a.x*b.y-a.y*b.x; } double mul(Point p0,Point p1,Point p2) { return cross(p1-p0,p2-p0); } double dis(Point a) { return a.x*a.x+a.y*a.y; } double area() { return fabs(cross(p[1]-p[3],p[2]-p[3]))/2; } bool seginter(pointt a1,pointt a2,pointt b1,pointt b2) { double c1 = cross(a2-a1,b1-a1),c2 = cross(a2-a1,b2-a1), c3 = cross(b2-b1,a1-b1),c4 = cross(b2-b1,a2-b1); return dcmp(c1)*dcmp(c2)<0&&dcmp(c3)*dcmp(c4)<0; } struct Circle Circumcircle() { Circle tmp; double a,b,c,c1,c2; double xa,ya,xb,yb,xc,yc; a = sqrt(dis(p[3]-p[1])); b = sqrt(dis(p[1]-p[2])); c = sqrt(dis(p[2]-p[3])); //根据s = a*b*c/R/4,求半径 tmp.r = (a*b*c)/(area()*4.0); xa = p[3].x; ya = p[3].y; xb = p[1].x; yb = p[1].y; xc = p[2].x; yc = p[2].y; c1 = (dis(p[3])-dis(p[1]))/2; c2 = (dis(p[3])-dis(p[2]))/2; tmp.center.x = (c1*(ya-yc)-c2*(ya-yb))/((xa-xb)*(ya-yc)-(xa-xc)*(ya-yb)); tmp.center.y = (c1*(xa-xc)-c2*(xa-xb))/((ya-yb)*(xa-xc)-(ya-yc)*(xa-xb)); return tmp; } int main() { int i; double r; int w0,w1,h0,h1; for(i = 1; i <= 3 ; i++) scanf("%lf%lf",&p[i].x,&p[i].y); Circle cc = Circumcircle(); r = cc.r; Point q[5]; for(i = 1 ;i < 5 ;i++) q[i] = cc.center; q[1].x-=r,q[2].x+=r,q[3].y-=r,q[4].y+=r; if(!seginter(q[1],p[3],p[1],p[2])) w0 = floor(q[1].x+eps); else w0 = floor(min(p[1].x,p[2].x)+eps); if(!seginter(q[2],p[3],p[1],p[2])) w1 = ceil(q[2].x-eps); else w1 = ceil(max(p[1].x,p[2].x)-eps); if(!seginter(q[3],p[3],p[1],p[2])) h0 = floor(q[3].y+eps); else h0 = floor(min(p[1].y,p[2].y)+eps); if(!seginter(q[4],p[3],p[1],p[2])) h1 = ceil(q[4].y-eps); else h1 = ceil(max(p[1].y,p[2].y)-eps); printf("%d\n",(h1-h0)*(w1-w0)); return 0; }
View Code
相关文章推荐
- 第274题正三角形的外接圆面积
- ACM-正三角形的外接圆面积(经典算法)
- [计算几何]POJ 1266 三角形的外接圆 圆的参数方程
- NYOJ 274 正三角形的外接圆面积
- POJ 1329 求三角形外接圆
- 正三角形的外接圆面积
- 三角形外接圆的圆心,向量旋转问题,求点(x1,y1)绕点(0,0)旋转a后坐标
- 求三维空间中的三角形外接圆圆心坐标的算法
- 三角形的内切圆和外接圆--【英雄会】
- 有多个点,求任意三个点组成的三角形的外接圆的最大半径
- HDU4720+三角形外接圆
- 正三角形的外接圆面积
- HDOJ 4720 Naive and Silly Muggles 三角形外接圆
- matlab实现三角形的外接圆与内接圆
- FZU 1382(求三角形的外接圆与内切圆)
- 三角形内切圆与外接圆的面积比
- hdu4720 三角形的外接圆
- 274 正三角形的外接圆面积
- pku2242 正弦+余弦求三点组成的三角形外接圆周长
- poj1329 解析几何-三角形求外接圆