博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
计算几何模板 ①
阅读量:4690 次
发布时间:2019-06-09

本文共 1504 字,大约阅读时间需要 5 分钟。

包含一些点与直线,线段的操作

凸包的构建与判断之类的操作

#include
#include
#include
#include
#include
#include
using namespace std;const double eps=1e-6;const double Pi=acos(-1.00);inline int dcmp(double x){ if(x>eps)return 1; return x<-eps?-1:0;}struct Vector{ double x,y; Vector(double X=0,double Y=0) { x=X,y=Y; } bool operator < (const Vector &b)const { return dcmp(x-b.x)==0?y
0;}void sort_point(Point *s,int L,int R,Point base){ Base=base; sort(s+L,s+1+R,cmp_ang); return;}struct Polygon{ Point node[10025]; Line edge[10025]; int cnt; double C; double A; void build_edge() { for(int i=1;i
0)ans++; } else if(on_seg(s2,ray)) { if(dcmp(s2.y-s1.y)>0)ans++; } else if(is_cross(ray,edge[i]))ans++; } if(ans%2==1)return 1; return -1; } bool circle_is_in_polygon(Circle a) { if(is_in_polygon(a.O)<0)return false; for(int i=1;i<=cnt;i++) if(dcmp(dist(a.O,get_nearest_point_on_segment(a.O,edge[i]))+eps-a.R)<0)return false; return true; } void get_convex_hull(Point *s,int num) { if(num==0) { cnt=0; return; } if(num==1) { cnt=1; node[1]=s[1]; return; } if(num==2) { cnt=2; node[2]=s[2]; node[1]=s[1]; return ; } for(int i=1;i<=num;i++) if(s[i]
=2&&dcmp(cross(node[cnt]-node[cnt-1],s[i]-node[cnt-1]))<=0)cnt--; node[++cnt]=s[i]; } return; } double get_Circumference() { C=0; for(int i=1;i<=cnt;i++) C+=dist(edge[i].s,edge[i].e); return C; } double get_Area() { A=0; for(int i=1;i

转载于:https://www.cnblogs.com/Harry-bh/p/9998491.html

你可能感兴趣的文章
C#中StreamReader读取中文出现乱码
查看>>
使用BufferedReader的时候出现的问题
查看>>
linux安装图形界面
查看>>
博弈论之入门小结
查看>>
解决IE8下opacity属性失效问题,无法隐藏元素
查看>>
批处理文件中的路径问题
查看>>
hibernate出现No row with the given identifier exists问题
查看>>
为什么wait()和notify()属于Object类
查看>>
PHP 在5.1.* 和5.2.*之间 PDO数据库操作中的不同!
查看>>
导入properties时的坑
查看>>
配置NRPE的通讯
查看>>
shp系列(一)——利用C++进行shp文件的读(打开)与写(创建)开言
查看>>
匹配两个空格之间的字符。。。
查看>>
CSS 文字溢出 变成省略号 ...
查看>>
Spring事务
查看>>
java编程基础(三)流程控制语句
查看>>
让数据库跑的更快的7个MySQL优化建议
查看>>
jquery 取id模糊查询
查看>>
解决在vue中,自用mask模态框出来后,下层的元素依旧可以滑动的问题
查看>>
修改node节点名称
查看>>