三角剖分求多边形面积的交 HDU3060
//三角剖分求多边形面积的交 HDU3060 #include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std; const int maxn = ;
const int maxisn = ;
const double eps = 1e-;
const double pi = acos(-1.0); int dcmp(double x) {
if(x > eps) return ;
return x < -eps ? - : ;
} struct Point {
double x, y;
Point() {
x = y = ;
}
Point(double a, double b) {
x = a, y = b;
}
inline Point operator-(const Point &b)const {
return Point(x - b.x, y - b.y);
}
inline Point operator+(const Point &b)const {
return Point(x + b.x, y + b.y);
}
inline double dot(const Point &b)const {
return x * b.x + y * b.y;
}
inline double cross(const Point &b, const Point &c)const {
return (b.x - x) * (c.y - y) - (c.x - x) * (b.y - y);
}
}; Point LineCross(const Point &a, const Point &b, const Point &c, const Point &d) {
double u = a.cross(b, c), v = b.cross(a, d);
return Point((c.x * v + d.x * u) / (u + v), (c.y * v + d.y * u) / (u + v));
} double PolygonArea(Point p[], int n) {
if(n < ) return 0.0;
double s = p[].y * (p[n - ].x - p[].x);
p[n] = p[];
for(int i = ; i < n; ++ i)
s += p[i].y * (p[i - ].x - p[i + ].x);
return fabs(s * 0.5);
} double CPIA(Point a[], Point b[], int na, int nb) { //ConvexPolygonIntersectArea
Point p[maxisn], tmp[maxisn];
int i, j, tn, sflag, eflag;
a[na] = a[], b[nb] = b[];
memcpy(p, b, sizeof(Point) * (nb + ));
for(i = ; i < na && nb > ; ++ i) {
sflag = dcmp(a[i].cross(a[i + ], p[]));
for(j = tn = ; j < nb; ++ j, sflag = eflag) {
if(sflag >= ) tmp[tn ++] = p[j];
eflag = dcmp(a[i].cross(a[i + ], p[j + ]));
if((sflag ^ eflag) == -)
tmp[tn ++] = LineCross(a[i], a[i + ], p[j], p[j + ]);
}
memcpy(p, tmp, sizeof(Point) * tn);
nb = tn, p[nb] = p[];
}
if(nb < ) return 0.0;
return PolygonArea(p, nb);
} double SPIA(Point a[], Point b[], int na, int nb) { //SimplePolygonIntersectArea
int i, j;
Point t1[], t2[];
double res = , if_clock_t1, if_clock_t2;
a[na] = t1[] = a[], b[nb] = t2[] = b[];
for(i = ; i < na; ++ i) {
t1[] = a[i - ], t1[] = a[i];
if_clock_t1 = dcmp(t1[].cross(t1[], t1[]));
if(if_clock_t1 < ) std::swap(t1[], t1[]);
for(j = ; j < nb; ++ j) {
t2[] = b[j - ], t2[] = b[j];
if_clock_t2 = dcmp(t2[].cross(t2[], t2[]));
if(if_clock_t2 < ) std::swap(t2[], t2[]);
res += CPIA(t1, t2, , ) * if_clock_t1 * if_clock_t2;
}
}
return PolygonArea(a, na) + PolygonArea(b, nb) - res;
} Point p1[maxn], p2[maxn];
int n1, n2; int main() {
int i;
while(scanf("%d%d", &n1, &n2) != EOF) {
for(i = ; i < n1; ++ i) scanf("%lf%lf", &p1[i].x, &p1[i].y);
for(i = ; i < n2; ++ i) scanf("%lf%lf", &p2[i].x, &p2[i].y);
printf("%.2f\n", SPIA(p1, p2, n1, n2) + eps);
}
return ;
}
三角剖分求多边形面积的交 HDU3060的更多相关文章
- hdu1255 覆盖的面积 线段树+里离散化求矩形面积的交
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 求矩形面积的交的线段树题目,刚做了求并的题目,再做这个刚觉良好啊,只要再加一个表示覆盖次数大于1 ...
- hdu 2036 求多边形面积 (凸、凹多边形)
<题目链接> Problem Description “ 改革春风吹满地,不会AC没关系;实在不行回老家,还有一亩三分地.谢谢!(乐队奏乐)” 话说部分学生心态极好,每天就知道游戏,这次考 ...
- hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)
Area Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- poj 1654:Area 区域 ---- 叉积(求多边形面积)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19398 Accepted: 5311 利用叉积求多边形面 ...
- [poj] 3907 Build Your Home || 求多边形面积
原题 多组数据,到0为止. 每次给出按顺序的n个点(可能逆时针,可能顺时针),求多边形面积(保留整数) 多边形面积为依次每条边(向量)叉积/2的和 \(S=\sum _{i=1}^{n-1}p[i]* ...
- HDU - 2036 改革春风吹满地 叉乘法求多边形面积
改革春风吹满地 “ 改革春风吹满地, 不会AC没关系; 实在不行回老家, 还有一亩三分地. 谢谢!(乐队奏乐)” 话说部分学生心态极好,每天就知道游戏,这次考试如此简单的题目,也是云里雾里,而且,还竟 ...
- 使用Delaunay三角剖分解决求多边形面积的问题
朋友那边最近有个需求,需要框选一个选区,然后根据选区中的点求出面积.并且让我尝试用Delaunay来解决 似乎音译过来应该是德诺类 大致如下: 我在github上找了一个可以用的Delaunay库 h ...
- Area - POJ 1654(求多边形面积)
题目大意:从原点开始,1-4分别代表,向右下走,向右走,向右上走,向下走,5代表回到原点,6-9代表,向上走,向左下走,向左走,向左上走.求出最后的多边形面积. 分析:这个多边形面积很明显是不规则的, ...
- poj 1654 Area(计算几何--叉积求多边形面积)
一个简单的用叉积求任意多边形面积的题,并不难,但我却错了很多次,double的数据应该是要转化为long long,我转成了int...这里为了节省内存尽量不开数组,直接计算,我MLE了一发...,最 ...
随机推荐
- java.lang.ClassNotFoundException: org.springframework.context.event.GenericApplicationListener ----good
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/event/GenericApplicationListe ...
- mysql中的连接
SQL join 用于根据两个或多个表中的列之间的关系,从这些表中查询数据. join可以分为内连接和外连接,外连接分为左连接.右连接和全连接 现有两个表 员工表和部门表 员工表 部门表 1.内连接( ...
- [原]poj-2680-Choose the best route-dijkstra(基础最短路)
题目大意: 已知n 个点,m条路线,s为终点:给出m条路线及其权值:给出w个起点,求最短路! 思路:基础的dijkstra,有向无环正权最短路,只要把终点和起点 reverse考虑便可. AC代码如下 ...
- Java中什么时候使用构造方法
JAVA是面向对象的语言,面向对象不是这么直接简单,它的设计思想就是要代码重用.即我以前干过类似的事,那么我找出以前可以用到的代码,完成一部分.以前没有的我重新写.这样就有了类.有了类,就是有了可以重 ...
- sql语句中能有中文 空格
EXEC dbo.usp_execute_sql_Prod 'SELECT * FROM dbo.QuanVerify_Log where ticketcode = ''3783665132'' ' ...
- Newtonsoft.Json序列化和反序列之javascriptConvert.SerializeObject,DeserializeObject,JsonWriter,JsonReader
这里下载:http://www.newtonsoft.com/products/json/安装: 1.解压下载文件,得到Newtonsoft.Json.dll 2.在项目中添加引用.. jav ...
- 通过两个GPS计算两个GPS点的距离
public static double GetDistance(double lat1, double lng1, double lat2, double lng2) { double radLat ...
- D3D渲染流程--转载
http://www.cnblogs.com/ixnehc/articles/1282350.html 先从最基础的写起吧,关于Device的渲染流程. D3D9的Device就是D3D给我们提供的一 ...
- nginx fastcgi php-fpm的关系梳理
CGI(Common Gateway Interface)CGI全称是“公共网关接口”(Common Gateway Interface),HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具 ...
- List排序的两种简便方式
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace List ...