diff options
author | taw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-02-05 21:12:57 +0000 |
---|---|---|
committer | taw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-02-05 21:12:57 +0000 |
commit | 05b5d261682b9136fb46476a64eab6980b0dba64 (patch) | |
tree | d7faa450b69cf2104ffff7fc89a95914284d23af /src/utils.c |
Initial import
git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@1 bf6ca9ba-c028-0410-8290-897cf20841d1
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 0000000..ce7c7f3 --- /dev/null +++ b/src/utils.c @@ -0,0 +1,44 @@ +/* + * utils.c + * + * Utility stuff + * + * (c) 2007 Thomas White <taw27@cam.ac.uk> + * dtr - Diffraction Tomography Reconstruction + * + */ + +#include <math.h> + +/* Return the MOST POSITIVE of two numbers */ +unsigned int biggest(signed int a, signed int b) { + if ( a>b ) { + return a; + } + return b; +} + +/* Return the LEAST POSITIVE of two numbers */ +unsigned int smallest(signed int a, signed int b) { + if ( a<b ) { + return a; + } + return b; +} + +double distance(double x1, double y1, double x2, double y2) { + return sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)); +} + +double modulus(double x, double y, double z) { + return sqrt(x*x + y*y + z*z); +} + +/* Angle between two vectors. Answer in degrees */ +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; + +} |