Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

trigo.cpp

Go to the documentation of this file.
00001 /* *************************************************************************************
00002         Writer:         Sebastien Bloc
00003         Copyright:      2003-2004
00004         eMail:          sebastien.bloc@free.fr
00005         URL:            http://mignonsoft.free.fr
00006 
00007         This program is free software; you can redistribute it and/or
00008         modify it under the terms of the GNU General Public License
00009         as published by the Free Software Foundation; either version 2
00010         of the License, or (at your option) any later version.
00011 
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU General Public License for more details.
00016         http://www.gnu.org/copyleft/gpl.html
00017 ************************************************************************************* */
00018 
00019 #include "trigo.h"
00020 
00021 // borne a un angle de [0,2*PI[
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         // si nb de point impaires, ne change rien
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 }

Generated on Fri Aug 20 19:19:51 2004 for 3d Controls by doxygen 1.3.6