aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authortaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2007-08-30 12:13:38 +0000
committertaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2007-08-30 12:13:38 +0000
commit0126d58f87dae943396f3701d83ccb1686143568 (patch)
tree7ec3c5c995e5b31eac60459d58bd87fda6b76f67 /src/utils.c
parentba227b40f3d7f16753f356f005fc78d8e57175af (diff)
angle_between now answers in radians
git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@94 bf6ca9ba-c028-0410-8290-897cf20841d1
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/utils.c b/src/utils.c
index 35f4b88..eaaa036 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -13,6 +13,8 @@
#include <math.h>
#include <gsl/gsl_matrix.h>
+#include "utils.h"
+
/* Return the MOST POSITIVE of two numbers */
unsigned int biggest(signed int a, signed int b) {
if ( a>b ) {
@@ -37,13 +39,18 @@ double modulus(double x, double y, double z) {
return sqrt(x*x + y*y + z*z);
}
-/* Angle between two vectors. Answer in degrees */
+/* Angle between two vectors. Answer in radians */
double angle_between(double x1, double y1, double z1, double x2, double y2, double z2) {
double mod1 = modulus(x1, y1, z1);
double mod2 = modulus(x2, y2, z2);
- return ((acos((x1*x2 + y1*y2 + z1*z2) / (mod1*mod2)))/M_PI) * 180;
+ return acos( (x1*x2 + y1*y2 + z1*z2) / (mod1*mod2) );
+
+}
+/* As above, answer in degrees */
+double angle_between_d(double x1, double y1, double z1, double x2, double y2, double z2) {
+ return rad2deg(angle_between(x1, y1, z1, x2, y2, z2));
}
/* Wavelength of an electron (in m) given accelerating potential (in V) */