diff options
author | taw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-08-30 12:13:38 +0000 |
---|---|---|
committer | taw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-08-30 12:13:38 +0000 |
commit | 0126d58f87dae943396f3701d83ccb1686143568 (patch) | |
tree | 7ec3c5c995e5b31eac60459d58bd87fda6b76f67 /src | |
parent | ba227b40f3d7f16753f356f005fc78d8e57175af (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')
-rw-r--r-- | src/ipr.c | 6 | ||||
-rw-r--r-- | src/utils.c | 11 | ||||
-rw-r--r-- | src/utils.h | 1 |
3 files changed, 13 insertions, 5 deletions
@@ -123,17 +123,17 @@ static Basis *ipr_choose_initial_basis(ControlContext *ctx) { angle_works = 1; if ( basis->a.modulus != 1e30 ) { - double angle = angle_between(reflection->x, reflection->y, reflection->z, basis->a.x, basis->a.y, basis->a.z); + double angle = angle_between_d(reflection->x, reflection->y, reflection->z, basis->a.x, basis->a.y, basis->a.z); if ( angle < 20 ) angle_works = 0; if ( angle > 160 ) angle_works = 0; } if ( basis->b.modulus != 1e30 ) { - double angle = angle_between(reflection->x, reflection->y, reflection->z, basis->b.x, basis->b.y, basis->b.z); + double angle = angle_between_d(reflection->x, reflection->y, reflection->z, basis->b.x, basis->b.y, basis->b.z); if ( angle < 20 ) angle_works = 0; if ( angle > 160 ) angle_works = 0; } if ( basis->c.modulus != 1e30 ) { - double angle = angle_between(reflection->x, reflection->y, reflection->z, basis->c.x, basis->c.y, basis->c.z); + double angle = angle_between_d(reflection->x, reflection->y, reflection->z, basis->c.x, basis->c.y, basis->c.z); if ( angle < 20 ) angle_works = 0; if ( angle > 160 ) angle_works = 0; } 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) */ diff --git a/src/utils.h b/src/utils.h index ff49fea..99fc748 100644 --- a/src/utils.h +++ b/src/utils.h @@ -24,6 +24,7 @@ extern unsigned int smallest(signed int a, signed int b); extern double distance(double x1, double y1, double x2, double y2); extern double modulus(double x, double y, double z); extern double angle_between(double x1, double y1, double z1, double x2, double y2, double z2); +extern double angle_between_d(double x1, double y1, double z1, double x2, double y2, double z2); extern double lambda(double voltage); extern void matrix_renormalise(gsl_matrix *m); |