极角排序

typedef struct P
{
    double x,y;
}P;
/*bool cmp1(P a,P b)//在这里一定要注意 atan2函数y写在逗号前 返回的极角范围为-π~π
{
    if(atan2(a.y,a.x)==atan2(b.y,b.x))return a.x<b.x;
    else return atan2(a.y,a.x)<atan2(b.y,b.x);
}*/
double compare(P c,P a,P b){
    return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
}
double xx=0.0,yy=0.0;
bool cmp2(P a,P b)
{
    P c;//极点(xx,yy)
    c.x=xx;
    c.y=yy;
    if(compare(c,a,b)==0)
        return a.x<b.x;
    else
        return compare(c,a,b)>0.0;
}

 

posted @ 2020-10-13 15:49  yesuweiYYYY  阅读(102)  评论(0编辑  收藏  举报