aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ipr.c6
-rw-r--r--src/utils.c11
-rw-r--r--src/utils.h1
3 files changed, 13 insertions, 5 deletions
diff --git a/src/ipr.c b/src/ipr.c
index 6df83c3..9a0db00 100644
--- a/src/ipr.c
+++ b/src/ipr.c
@@ -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);