summaryrefslogtreecommitdiffstats
path: root/kspaceduel/mathroutines.cpp
diff options
context:
space:
mode:
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;
+}