summaryrefslogtreecommitdiffstats
path: root/kspaceduel/mathroutines.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitc90c389a8a8d9d8661e9772ec4144c5cf2039f23 (patch)
tree6d8391395bce9eaea4ad78958617edb20c6a7573 /kspaceduel/mathroutines.cpp
downloadtdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.tar.gz
tdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kspaceduel/mathroutines.cpp')
-rw-r--r--kspaceduel/mathroutines.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/kspaceduel/mathroutines.cpp b/kspaceduel/mathroutines.cpp
new file mode 100644
index 00000000..4597a3ad
--- /dev/null
+++ b/kspaceduel/mathroutines.cpp
@@ -0,0 +1,41 @@
+#include "mathroutines.h"
+#include "math.h"
+
+double rectToAngle(double x,double y)
+{
+ double phi=0;
+ if(fabs(x)<1e-6)
+ {
+ if(y>0)
+ phi=M_PI_2;
+ else
+ phi=-M_PI_2;
+ }
+ else
+ {
+ phi=atan(y/x);
+ if(x<0)
+ phi+=M_PI;
+ }
+ if(phi>M_PI)
+ phi-=2*M_PI;
+ return phi;
+}
+
+double average(double phi1,double phi2)
+{
+ return phi2+difference(phi1,phi2)/2.0;
+}
+
+double difference(double phi1,double phi2)
+{
+ double dif;
+
+ dif=phi1-phi2;
+ while(dif>M_PI)
+ dif-=2*M_PI;
+ while(dif<-M_PI)
+ dif+=2*M_PI;
+
+ return dif;
+}