aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2013-03-08 10:49:49 +0100
committerThomas White <taw@physics.org>2013-04-17 17:33:48 +0200
commit3a348d3f7e2586440590747c1b921b8ce6dbc0e1 (patch)
treeb7f357e7c68b5f549491769bd194826eeb1dc64b /libcrystfel/src
parentf8de3ad3f3410b95180f569d99b9b1f9bd9523ab (diff)
Work on post refinement
Brought across from "tom/pr" Conflicts: src/indexamajig.c src/post-refinement.c tests/pr_gradient_check.c
Diffstat (limited to 'libcrystfel/src')
-rw-r--r--libcrystfel/src/utils.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/libcrystfel/src/utils.h b/libcrystfel/src/utils.h
index b75693db..1adb69e6 100644
--- a/libcrystfel/src/utils.h
+++ b/libcrystfel/src/utils.h
@@ -139,6 +139,11 @@ static inline double modulus(double x, double y, double z)
return sqrt(x*x + y*y + z*z);
}
+static inline double modulus2d(double x, double y)
+{
+ return sqrt(x*x + y*y);
+}
+
static inline double modulus_squared(double x, double y, double z) {
return x*x + y*y + z*z;
}
@@ -165,6 +170,21 @@ static inline double angle_between(double x1, double y1, double z1,
return acos(cosine);
}
+/* Answer in radians */
+static inline double angle_between_2d(double x1, double y1,
+ double x2, double y2)
+{
+ double mod1 = modulus2d(x1, y1);
+ double mod2 = modulus2d(x2, y2);
+ double cosine = (x1*x2 + y1*y2) / (mod1*mod2);
+
+ /* Fix domain if outside due to rounding */
+ if ( cosine > 1.0 ) cosine = 1.0;
+ if ( cosine < -1.0 ) cosine = -1.0;
+
+ return acos(cosine);
+}
+
static inline int within_tolerance(double a, double b, double percent)
{
double tol = fabs(a) * (percent/100.0);