A detailed description of the polar angle
Noun Interpretation:
In the plane to take a fixed point o, called the Pole, a ray of ox, called the polar axis, and then select a length unit and angle of the square direction (usually counterclockwise). For any bit of m in the plane, the length of the segment OM is represented by the ρ (sometimes denoted by R), θ denotes the angle from ox to OM, ρ is called the polar diameter of point m, θ is called the polar angle of point m, and the order number pair (ρ,θ) is called the polar coordinates of M.
Four kinds of polar sort codes in detail:
1 struct Point2 {3 Doublex, y;4 };5 6 DoubleCrossDoubleX1,DoubleY1,DoubleX2,Doubley2)//Calculate cross Product7 {8 return(x1*y2-x2*y1);9 }Ten One DoubleCompare (Point a,point b,point c) A { - returnCross ((b.x-a.x), (B.Y-A.Y), (c.x-a.x), (c.y-a.y)); -}
1, the use of complex class by the polar angle from small to large order:
1 BOOLCmp0 (Constpoint& A,Constpoint& b)//using the complex class to sort from small to large by polar angle2 {3complex<Double> C1 (A.X,A.Y);//header file #include <complex>4complex<Double>C2 (B.X,B.Y);5 if(ARG (c1) = =arg (C2))6 returna.x<b.x;7 returnARG (C1) <arg (C2);8}
2. Use the atan2 () function to sort from small to large by the polar angle
1 bool CMP1 (point a,point B)// using the atan2 () function to sort from small to large by the polar angle 2{3 if (ATAN2 (a.y,a.x)! =atan2 (b.y,b.x)) 4 return atan2 (a.y,a.x) <atan2 (b.y,b.x); 5 Else return a.x<b.x; 6 }
3, using the cross product by the polar angle from small to large order
1 BOOLCMP2 (Point A,point B)//using cross product to sort from small to large by polar angle2 {3Point C;//origin Point4c.x =0;5C.Y =0;6 if(Compare (c,a,b) = =0)7 returna.x<b.x;8 Else returnCompare (C,a,b) >0;9}
4, first by quadrant from small to large sort and then by the polar angle from small to large sort
1 intQuadrant (Point A) //quadrant sort 2 {3 if(a.x>0&&a.y>=0)return 1;4 if(a.x<=0&&a.y>0)return 2;5 if(a.x<0&&a.y<=0)return 3;6 if(a.x>=0&&a.y<0)return 4;7 }8 9 Ten BOOLCmp3 (Point A,point B)//Sort by quadrant from small to large and then from small to large by polar angle One { A if(Quadrant (a) = =Quadrant (b)) - returnCmp1 (A, b); - ElseQuadrant (a) <Quadrant (b); the}
This article is a personal essay, if there are inappropriate, hope that the big boys more advice.
If you can provide small help to Bo friends, it is a great honor.
A detailed description of the polar angle: