Calculate geometry template to write a lot of content ...
I'm tired of writing ... Just write this and put it up.
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <vector>#define MAXDBL 1e20#define EPS 1e-9#define PI ACOs ( -1)using namespace STD;structpoint{Doublex, y; PointDouble_x=0,Double_y=0): X (_x), Y (_y) {}BOOL operator< (Constpoint& a)Const{returnx==a.x?y<a.y:x<a.x; }};typedefPoint Vector; Vectoroperator+ (Vector a,vector B)//Vector subtraction{returnVector (A.X+B.X,A.Y+B.Y);} Vectoroperator-(Vector a,vector B) {returnVector (A.X-B.X,A.Y-B.Y);} Vectoroperator* (Vector A,DoubleK) {returnVector (a.x*k,a.y*k);} Vectoroperator/(Vector A,DoubleK) {returnVector (a.x/k,a.y/k);}BOOL operator= = (Vector a,vector B) {return fabs(a.x-b.x) <eps&&fabs(A.Y-B.Y) <eps;}DoubleSqrDoublex) {returnX*x;}DoubleDis (point a,point B)//Point distance{return sqrt(Sqr (a.x-b.x) +SQR (A.Y-B.Y));} Point Point_sym (Point A,point B)//a about the symmetry point of B{returnPoint2*b.x-a.x,2*B.Y-A.Y);}DoubleDot (Vector a,vector b)//Vector dot product{returnA.X*B.X+A.Y*B.Y;}DoubleCross (Vector A,vector b)//Cross product{returna.x*b.y-a.y*b.x;}DoubleArea (Point A,point b,point c)//Area{Vector a=b-a,b=b-c;return fabs(Cross (b))/2;}DoubleLen (Vector A)//Vector length{return sqrt(Sqr (a.x) +SQR (A.Y));}DoubleAngle (Vector a,vector B)//Find the angle{return ACOs(Dot (A)/len (A)/len (B)); Vector rot (vector A,Doublerad//vector counterclockwise rotation rad radians{returnVector (a.x*Cos(RAD)-a.y*Sin(RAD), a.x*Sin(RAD) +a.y*Cos(RAD));} Vector Normal (vector A)//Counter-clockwise 90-degree unit vector{DoubleL=len (A);returnVector (-a.y/l,a.x/l);} Vector Unit (vector A)//unit vector based on the original vector{DoubleL=len (A);returna/l;}structline{point P; Vector v;//direction vector of points and lines passing through the lineLine (Point _p=point (0,0), Vector _v=vector (0,0): P (_p), V (_v) {}};BOOLOn_left (line L,point p)//point in line left/right{returnCross (L.V,P-L.P) >0;} Point Line_cross (line A,line B)//Straight line intersection{Vector u=a.p-b.p;DoubleT=cross (b.v,u)/cross (A.V,B.V);returnA.p+a.v*t;};DoubleDis_point_line (Point A,line B)//point to line distance{Point a=b.p,b=b.p+b.v; Vector u=a-a,v=b-a;return fabs(Cross (U,V))/len (v);};structcircle{point P;DoubleR Circle (Point _p,Double_r): P (_p), R (_r) {} point point (Doublerad) {returnPoint (p.x+r*Cos(RAD), p.y+r*Sin(RAD)); }}; vector<point>Line_cross_circle (line l,circle c)//intersection of lines and circles{Line Dia (C.p,normal (L.V)); Point Inter=line_cross (dia,l);DoubleD=dis_point_line (Inter,dia);if(c.r-d<0)return vector<point>();Doublelen=sqrt(Sqr (C.R)-sqr (d)); vector<point>V V.push_back (Inter-unit (L.V) *len); V.push_back (Inter+unit (L.V) *len);}intConvexhull (Point *p,intN,point *ch)//Convex bag{Sort (p+1, p+n+1);inttop=0, TMP; for(intI=1; i<=n;i++) { while(top>1&&cross (ch[top-1]-ch[top-2],p[i]-ch[top-2]) <=0) top--; Ch[++top]=p[i]; } tmp=top; for(inti=n-1; i>=1; i--) { while(Top>tmp&&cross (ch[top-1]-ch[top-2],p[i]-ch[top-2]) <=0) top--; Ch[++top]=p[i]; }returnTop;}DoubleCh_area (Point *ch,intN//Convex bag area{Doubleret=0; for(intI=1; i<n;i++) Ret+=area (ch[1],ch[i],ch[i+1]);returnRET;}DoubleCh_cir (Point *ch,intN//Convex Bao Zhouchang{Doubleret=0; for(intI=1; i<n;i++) Ret+=dis (ch[i],ch[i+1]); Ret+=dis (ch[n],ch[1]);returnRET;}intMain () {}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Template Consolidation" "Timely update" "Sinkhole" Computational geometry template