This article is made by Jason-Cow.
Welcome to reprint.
But please post the article's address.

 

在线笛卡尔坐标系绘图网站

核心思想

  1.积角排序

  2.双端队列维护半平面交

木有啦~~

 int HPI(L*l,int n,D*ans){
int head,tail,m=;D*P=new D[n];L*q=new L[n];
sort(l+,l+n+),q[head=tail=]=l[];
for(int i=;i<=n;i++){
while(head<tail && !Left(l[i],P[tail-]))tail--;
while(head<tail && !Left(l[i],P[head])) head++;
q[++tail]=l[i];//双端队列<( ̄3 ̄)>
if(fabs(Cross(q[tail].v,q[tail-].v))<eps){
tail--;//判断Cross(q[tail].v,q[tail-1].v)==0♪(^∇^*)
if(Left(q[tail],l[i].P))q[tail]=l[i];
}
if(head<tail)P[tail-]=Intersect(q[tail-],q[tail]);
}
while(head<tail && !Left(q[head],P[tail-]))tail--;
if(tail-head<=)return ;
P[tail]=Intersect(q[tail],q[head]);
for(int i=head;i<=tail;i++)ans[++m]=P[i];
return m;
}

多边形相关

db Area(D*R,int n){
db S=0.0;
for(int i=;i<n;i++)S+=Cross(R[i]-R[],R[i+]-R[]);
return S/;
} db Length(D*R,int n){
db C=0.0;
for(int i=;i<=n;i++)C+=Dis(R[i],R[i-]);
return C+Dis(R[n],R[]);
}

主程序

 L l[];D A[];
int main(){
for(int n;scanf("%d",&n)&&n;){
for(int i=;i<=n;i++){
db a,b,c,d;
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
D A(a,b),B(c,d);
l[i]=L(A,B-A);
}
int m=HPI(l,n,A);
cout<<"m="<<m<<endl;
for(int i=;i<=m;i++)printf("(%.4lf,%.4lf)\n",A[i].x,A[i].y);
printf("S=%.2lf\n",Area(A,m));
printf("C=%.2lf\n",Length(A,m));
}
return ;
}

读入,如图(橙、红、蓝、绿)

4
2 1 1 2
1 2 0 1
1 0 2 1
0 1 1 0

输出

m=4
(0.0000,1.0000)
(1.0000,0.0000)
(2.0000,1.0000)
(1.0000,2.0000)
S=2.00
C=5.66

读入

6
1 2 0 1
0 1.8 0.8 0.2
0 1 1 0
1 0 2 1
3 0 1 2
0.6 1.6 0 0.7

输出

m=6
(0.6000,1.6000)
(0.3143,1.1714)
(0.8000,0.2000)
(1.0000,0.0000)
(2.0000,1.0000)
(1.0000,2.0000)
S=1.76
C=5.28

完整代码

 #include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define sqr(x) ((x)*(x))
#define RG register
#define op operator
#define IL inline
typedef double db;
typedef bool bl;
const db pi=acos(-1.0),eps=1e-;
struct D{
db x,y;
D(db x=0.0,db y=0.0):x(x),y(y){}
};
typedef D V;//不知道什么鬼,emacs 将 operator -> op 会萎掉 对!不!齐!
bl operator<(D A,D B){return A.x<B.x||(A.x==B.x&&A.y<B.y);}
V operator+(V A,V B){return V(A.x+B.x,A.y+B.y);}
V operator-(V A,V B){return V(A.x-B.x,A.y-B.y);}
V operator*(V A,db N){return V(A.x*N,A.y*N);}
V operator/(V A,db N){return V(A.x/N,A.y/N);} db Ang(db x){return(x*180.0/pi);}
db Rad(db x){return(x*pi/180.0);}
V Rotate(V A,db a){return V(A.x*cos(a)-A.y*sin(a),A.x*sin(a)+A.y*cos(a));}
db Dis(D A,D B){return sqrt(sqr(A.x-B.x)+sqr(A.y-B.y));}
db Cross(V A,V B){return A.x*B.y-A.y*B.x;} db Area(D*R,int n){
db S=0.0;
for(int i=;i<n;i++)S+=Cross(R[i]-R[],R[i+]-R[]);
return S/;
} db Length(D*R,int n){
db C=0.0;
for(int i=;i<=n;i++)C+=Dis(R[i],R[i-]);
return C+Dis(R[n],R[]);
} struct L{
D P,v;
db a;
L(){}
L(D P,V v):P(P),v(v){a=atan2(v.y,v.x);}
bool operator<(const L x)const{return a<x.a;}
}; D Intersect(L a,L b){
V u=a.P-b.P;
return a.P+a.v*(Cross(b.v,u)/Cross(a.v,b.v));
} bool Left(L l,D A){
return Cross(l.v,A-l.P)>;
} int HPI(L*l,int n,D*ans){
int head,tail,m=;D*P=new D[n];L*q=new L[n];
sort(l+,l+n+),q[head=tail=]=l[];
for(int i=;i<=n;i++){
while(head<tail && !Left(l[i],P[tail-]))tail--;
while(head<tail && !Left(l[i],P[head])) head++;
q[++tail]=l[i];//双端队列<( ̄3 ̄)>
if(fabs(Cross(q[tail].v,q[tail-].v))<eps){
tail--;//判断Cross(q[tail].v,q[tail-1].v)==0♪(^∇^*)
if(Left(q[tail],l[i].P))q[tail]=l[i];
}
if(head<tail)P[tail-]=Intersect(q[tail-],q[tail]);
}
while(head<tail && !Left(q[head],P[tail-]))tail--;
if(tail-head<=)return ;
P[tail]=Intersect(q[tail],q[head]);
for(int i=head;i<=tail;i++)ans[++m]=P[i];
return m;
} L l[];
D A[];
int main(){
cout<<*sqrt()<<endl;
for(int n;scanf("%d",&n)&&n;){
for(int i=;i<=n;i++){
db a,b,c,d;
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
D A(a,b),B(c,d);
l[i]=L(A,B-A);
}
int m=HPI(l,n,A);
cout<<"m="<<m<<endl;for(int i=;i<=m;i++)printf("(%.4lf,%.4lf)\n",A[i].x,A[i].y);
printf("S=%.2lf\n",Area(A,m));
printf("C=%.2lf\n",Length(A,m));
}
return ;
}

HPI

计算几何-HPI的更多相关文章

  1. 计算几何-BZOJ2618-凸包的交-HPI

    This article is made by Jason-Cow.Welcome to reprint.But please post the article's address. bzoj2618 ...

  2. ACM/ICPC 之 计算几何入门-叉积-to left test(POJ2318-POJ2398)

    POJ2318 本题需要运用to left test不断判断点处于哪个分区,并统计分区的点个数(保证点不在边界和界外),用来做叉积入门题很合适 //计算几何-叉积入门题 //Time:157Ms Me ...

  3. HDU 2202 计算几何

    最大三角形 Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  4. ACM 计算几何中的精度问题(转)

    http://www.cnblogs.com/acsmile/archive/2011/05/09/2040918.html 计算几何头疼的地方一般在于代码量大和精度问题,代码量问题只要平时注意积累模 ...

  5. hdu 2393:Higher Math(计算几何,水题)

    Higher Math Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)

    Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a b ...

  7. [知识点]计算几何I——基础知识与多边形面积

    // 此博文为迁移而来,写于2015年4月9日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102vxaq.html 1.前言 ...

  8. POJ 1106 Transmitters(计算几何)

    题目链接 切计算几何,感觉计算几何的算法还不熟.此题,枚举线段和圆点的直线,平分一个圆 #include <iostream> #include <cstring> #incl ...

  9. TYVJ计算几何

    今天讲了计算几何,发几道水水的tyvj上的题解... 计算几何好难啊!@Mrs.General....怎么办.... 这几道题都是在省选之前做的,所以前面的Point运算啊,dcmp啊,什么什么的,基 ...

随机推荐

  1. java - GC垃圾收集器详解(三)

    以前收集器的特点 年轻代和老年代是各自独立且连续的内存块 年轻代收集必须使用单个eden+S0+S1进行复制算法 老年代收集扫描整个老年代区域 都是以尽可能少而快速地执行GC为设计原则 G1是什么 G ...

  2. AI: Uninformed search

    What is a search problem: A solution to a search problem is a sequence of actions (a path) from s0 t ...

  3. Postgresql Json Sql

    a detailed website about json sql query; official website: here, chinese version: here Json query: - ...

  4. 题解 P5733 【【深基6.例1】自动修正】

    题目传送门 分析: 1.这道题可以说是一个字符串的练习好题.我们先来了解一下字符串.在这道题中,建议使用\(string\) \(string\)是\(C++\).\(java\).\(VB\)等编程 ...

  5. gz、tar、zip、bz2压缩和解压缩命令

    gzip 压缩后的格式为:*.gz 这种压缩方式不能保存原文件:且不能压缩目录 命令举例:#压缩[root@localhost tmp]# gzip buodo[root@localhost tmp] ...

  6. flaskapp

    前置知识 https://blog.csdn.net/u013457794/article/details/88997699?depth_1-utm_source=distribute.pc_rele ...

  7. python多项式拟合:np.polyfit 和 np.polyld

    python数据拟合主要可采用numpy库,库的安装可直接用pip install numpy等. 1. 原始数据:假如要拟合的数据yyy来自sin函数,np.sin import numpy as ...

  8. Win10下Pytorch和配置和安装

    Pytorch的安装 注意:Pytorch的版本,cuda版本,cudnn版本,Python版本,nvidia驱动版本要相互对应,否则就会出现各种报错和问题,无法使用GPU加速计算! 查看nvida驱 ...

  9. Python发带附件的邮件

    python实现发送带附件的邮件 import smtplib from email.mime.text import MIMEText from email.mime.multipart impor ...

  10. doctype的意思

    <!DOCTYPE HTML>这句话在整个网页的最上头,意思是这个网页是一个用html5语法写的,因为还有html4和xhtml等语法. 为了兼容一些旧的页面,浏览器设置了两种解析模式:1 ...