资源描述:
《ACM国际大学生程序设计竞赛 -计算几何(源码)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、(1)凸包/凸包cug_1038/#include#includestructpoint{intx,y;}pp;pointp[100005];intstack[100005],top;intdis(pointa,pointb){return((a.x-b.x)(a.x-b.x)+(a.y-b.y)(a.y-b.y));}intmulti(pointb,pointc,pointa){return(b.x-a.x)(c.y-a.y)-(b.y-a.y)(c.x-a.x);}voidswap(pointp[
2、],ints,intt){pointtmp;tmp=p[s];p[s]=p[t];p[t]=tmp;}intcmp(constvoida,constvoidb){pointc=(point)a;pointd=(point)b;doublek=multi(c,d,pp);if(k<0)return1;elseif(k==0&&dis(c,pp)>=dis(d,pp))return1;elsereturn-1;}voidGraham(pointp[],intn,intstack[],int&top){inti,u;u=0;for(i=1;i<
3、n;i++){if(p[i].y==p[u].y&&p[i].x
=0){if(top==0)break;top--;}top++;stack[top]=i;}}intmain
4、(){intca,i,j,n;intarea;scanf("%d",&ca);for(i=1;i<=ca;i++){scanf("%d",&n);for(j=0;j5、---------------------------------------------------------------------------------------------------------------------(2)判断两条线段是否相交(平行,不平行)boolisIntersected(TPoints1,TPointe1,TPoints2,TPointe2){//判断线段是否相交//1.快速排斥试验判断以两条线段为对角线的两个矩形是否相交//2.跨立试验if((max(s1.x,e1.x)>=min(s2.x,e2
6、.x))&&(max(s2.x,e2.x)>=min(s1.x,e1.x))&&(max(s1.y,e1.y)>=min(s2.y,e2.y))&&65(max(s2.y,e2.y)>=min(s1.y,e1.y))&&(multi(s2,e1,s1)multi(e1,e2,s1)>=0)&&(multi(s1,e2,s2)multi(e2,e1,s2)>=0))returntrue;returnfalse;}(3)三角形的外接圆(已知不在同一直线上的三点求经过三点的圆)/三角形的外接圆pku_1329/#include
7、#includeconstdoubleeps=1e-6;typedefstructTPoint{doublex;doubley;}TPoint;typedefstructTTriangle{TPointt[3];}TTriangle;typedefstructTCircle{TPointcentre;doubler;}TCircle;doubledistance(TPointp1,TPointp2){//计算平面上两个点之间的距离returnsqrt((p1.x-p2.x)(p1.x-p2.x)+(p1.y-p2.y)(p
8、1.y-p2.y));}doubletriangleArea(TTrianglet){//已知三角形三个顶点的坐标,求三角形的面积returnfabs(t.t[0].xt.t[1].y+t.t