SVN_SILENT made messages (.desktop file)
[kdegames.git] / kspaceduel / mathroutines.cpp
blob37308d8261d3dc69d837f7cda4016ddc5972f5d5
1 /*
2 Copyright (C) 1998-2001 Andreas Zehender <az@azweb.de>
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #include "mathroutines.h"
20 #include "math.h"
22 double rectToAngle(double x,double y)
24 double phi=0;
25 if(fabs(x)<1e-6)
27 if(y>0)
28 phi=M_PI_2;
29 else
30 phi=-M_PI_2;
32 else
34 phi=atan(y/x);
35 if(x<0)
36 phi+=M_PI;
38 if(phi>M_PI)
39 phi-=2*M_PI;
40 return phi;
43 double average(double phi1,double phi2)
45 return phi2+difference(phi1,phi2)/2.0;
48 double difference(double phi1,double phi2)
50 double dif;
52 dif=phi1-phi2;
53 while(dif>M_PI)
54 dif-=2*M_PI;
55 while(dif<-M_PI)
56 dif+=2*M_PI;
58 return dif;