00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "trigo.h"
00020
00021
00022 double Bound2_PI(double angle)
00023 {
00024 int nbTours = (int)(angle/DOUBLE_PI);
00025 double angleRes = angle-nbTours*DOUBLE_PI;
00026 if (angleRes<0) angleRes = DOUBLE_PI+angleRes;
00027 return angleRes;
00028 }
00029
00040 BOOL GetTrigoSens(POINT *pt)
00041 {
00042 double angle1,angle2;
00043 int dx1=pt[1].x-pt[0].x;
00044 int dy1=pt[1].y-pt[0].y;
00045 int dx2=pt[2].x-pt[1].x;
00046 int dy2=pt[2].y-pt[1].y;
00047 angle1=atan2((double)dy1,(double)dx1);
00048 angle2=atan2((double)dy2,(double)dx2);
00049 return Bound2_PI(angle2-angle1)>PI?FALSE:TRUE;
00050 }
00051
00062 BOOL GetTrigoSens(POINT *pt,int nbPoints)
00063 {
00064 BOOL trigo=-2;
00065 for (int i=0;i<nbPoints-2;i++)
00066 {
00067 BOOL trigoCur = GetTrigoSens(pt+i);
00068 if (trigo==-2) trigo = trigoCur;
00069 if (trigoCur!=trigo)
00070 return -1;
00071 }
00072 return trigo;
00073 }
00074
00078 void ChangeTrigoSens(POINT *pt,int nbPoints)
00079 {
00080 POINT point;
00081
00082 for (int i=0,j=nbPoints-1;i<nbPoints/2;i++,j--)
00083 {
00084 point.x=pt[i].x;
00085 point.y=pt[i].y;
00086 pt[i].x=pt[j].x;
00087 pt[i].y=pt[j].y;
00088 pt[j].x=point.x;
00089 pt[j].y=point.y;
00090 }
00091 }
00092
00096 int GetNearExp2(int num)
00097 {
00098 int numExp2;
00099 for (numExp2=1;numExp2<num;numExp2<<=1);
00100 return numExp2;
00101 }
00102
00106 int IntFloorLog2(unsigned int x)
00107 {
00108 int a=0;
00109 while (x>>=1) ++a;
00110 return a;
00111 }
00112
00116 BOOL IsPow2(unsigned int x)
00117 {
00118 return ((x>0) && ((x&(x-1))==0));
00119 }