poj1266Cover an Arc(三角形外接圆)
求出三角形的外接圆,通过圆心和半径可以知道这个圆的上下左右最远点,分别判断这个四个点跟弧的两端点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-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y) {}
}p[];
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 ;
else return x<?-:;
}
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[]-p[],p[]-p[]))/;
}
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)<&&dcmp(c3)*dcmp(c4)<;
}
struct Circle Circumcircle()
{
Circle tmp;
double a,b,c,c1,c2;
double xa,ya,xb,yb,xc,yc;
a = sqrt(dis(p[]-p[]));
b = sqrt(dis(p[]-p[]));
c = sqrt(dis(p[]-p[]));
//根据s = a*b*c/R/4,求半径
tmp.r = (a*b*c)/(area()*4.0);
xa = p[].x;
ya = p[].y;
xb = p[].x;
yb = p[].y;
xc = p[].x;
yc = p[].y;
c1 = (dis(p[])-dis(p[]))/;
c2 = (dis(p[])-dis(p[]))/;
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 = ; i <= ; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
Circle cc = Circumcircle();
r = cc.r; Point q[];
for(i = ;i < ;i++)
q[i] = cc.center;
q[].x-=r,q[].x+=r,q[].y-=r,q[].y+=r; if(!seginter(q[],p[],p[],p[])) w0 = floor(q[].x+eps);
else w0 = floor(min(p[].x,p[].x)+eps); if(!seginter(q[],p[],p[],p[])) w1 = ceil(q[].x-eps);
else w1 = ceil(max(p[].x,p[].x)-eps); if(!seginter(q[],p[],p[],p[])) h0 = floor(q[].y+eps);
else h0 = floor(min(p[].y,p[].y)+eps); if(!seginter(q[],p[],p[],p[])) h1 = ceil(q[].y-eps);
else h1 = ceil(max(p[].y,p[].y)-eps); printf("%d\n",(h1-h0)*(w1-w0));
return ;
}
poj1266Cover an Arc(三角形外接圆)的更多相关文章
- POJ 1329 Circle Through Three Points(三角形外接圆)
题目链接:http://poj.org/problem?id=1329 #include<cstdio> #include<cmath> #include<algorit ...
- HDU4720+三角形外接圆
/* 几何 求给定三角形的外接圆圆心 方法:求解二元方程组 */ #include<stdio.h> #include<string.h> #include<math.h ...
- matlab练习程序(三角形外接圆)
三角形两边的垂直平分线就能确定外接圆. 结果如下: matlab代码如下: clear all;close all;clc; p=rand(,); %(x,y) cen1=(p(,:)+p(,:))/ ...
- poj1329Circle Through Three Points(三角形外接圆)
链接 套模板 不知道有没有x,y=0情况,不过这种情况都按+号输出的. #include <iostream> #include<cstdio> #include<cst ...
- 算法笔记_082:蓝桥杯练习 12-1三角形(Java)
目录 1 问题描述 2 解决方案 1 问题描述 问题描述 为二维空间中的点设计一个结构体,在此基础上为三角形设计一个结构体.分别设计独立的函数计算三角形的周长.面积.中心和重心.输入三个点,输出这 ...
- [GodLove]Wine93 Tarining Round #9
比赛链接: http://vjudge.net/contest/view.action?cid=48069#overview 题目来源: lrj训练指南---二维几何计算 ID Title Pro ...
- [转] POJ计算几何
转自:http://blog.csdn.net/tyger/article/details/4480029 计算几何题的特点与做题要领:1.大部分不会很难,少部分题目思路很巧妙2.做计算几何题目,模板 ...
- HDU 3007 Buried memory & ZOJ 1450 Minimal Circle
题意:给出n个点,求最小包围圆. 解法:这两天一直在学这个神奇的随机增量算法……看了这个http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066之后自己写了好久 ...
- RIA算法解决最小覆盖圆问题
一.概念引入 最小包围圆问题:对于给定的平面上甩个点所组成的一个集合P,求出P的最小包围圆,即包含P中所有点.半径最小的那个圆.也就是求出这个最小 包围圆的圆心位置和半径. ...
随机推荐
- easyui datagrid 每条数据后添加操作按钮
easyui datagrid 每条数据后添加“编辑.查看.删除”按钮 1.给datagrid添加操作字段:字段值 <table class="easyui-datagrid" ...
- 通达OA 同步中控考勤机 增强版
如果你用的是中控考勤机且考勤机能联网,那恭喜有福了! 最近发现考勤机提供web方式查询,经过调试可以用程序直接读取考勤机数据跨过考勤机软件及其access数据库,数据同步及时性.可靠性大幅提高. 通达 ...
- load-on-startup
在servlet的配置当中,<load-on-startup>1</load-on-startup>,一般出现在启动线程的servlet当中 含义是: 标记容器是否在启动的时候 ...
- C类地址
C类地址第1字节.第2字节和第3个字节为网络地址,第4个字节为主机地址.另外第1个字节的前三位固定为110. C类地址范围:192.0.0.1到223.255.255.255.(第1个字节的二进制值前 ...
- 20150813 Asp.net 关闭子窗体 刷新Tree控件
主窗体************************************************************************************ using System ...
- Ahui Writes Word
Ahui Writes Word Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- SQLite不支持的SQL语法总结
1 TOP 这是一个大家经常问到的问题,例如在SQLSERVER中可以使用如下语句来取得记录集中的前十条记录: SELECT TOP 10 * FROM [index] ORDER BY indexi ...
- uva 1025,城市的间谍
题目链接:https://uva.onlinejudge.org/external/10/1025.pdf 题意: 地铁是线性的,有n个站,编号(1~n),M1辆从左至右的车,和M2辆从右至左的车,发 ...
- PostgreSql安装
官网:http://www.postgresql.org/download/linux/redhat/ 一.安装 由于我的机子是centos6.2,所以选择RedHat的. 按照官网所说的进行安装: ...
- ZOJ 3593 One Person Game
One Person Game Time Limit: 2 Seconds Memory Limit: 65536 KB There is an interesting and simple ...