aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/diffraction.c2
-rw-r--r--src/utils.c32
-rw-r--r--src/utils.h1
3 files changed, 34 insertions, 1 deletions
diff --git a/src/diffraction.c b/src/diffraction.c
index bc3e685c..f262c9d1 100644
--- a/src/diffraction.c
+++ b/src/diffraction.c
@@ -173,7 +173,7 @@ struct rvec get_q(struct image *image, unsigned int xs, unsigned int ys,
q.v = k * sin(twothetay);
q.w = k - k * cos(twotheta);
- return q;
+ return quat_rot(q, image->orientation);
}
diff --git a/src/utils.c b/src/utils.c
index 75cdd884..7e6bf6ec 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -14,6 +14,7 @@
#include <stdio.h>
#include "utils.h"
+#include "image.h"
size_t skipspace(const char *s)
@@ -160,3 +161,34 @@ int quaternion_valid(struct quaternion q)
return 0;
}
+
+
+struct rvec quat_rot(struct rvec q, struct quaternion z)
+{
+ struct rvec res;
+ double t01, t02, t03, t11, t12, t13, t22, t23, t33;
+
+ t01 = z.w*z.x;
+ t02 = z.w*z.y;
+ t03 = z.w*z.z;
+ t11 = z.x*z.x;
+ t12 = z.x*z.y;
+ t13 = z.x*z.z;
+ t22 = z.y*z.y;
+ t23 = z.y*z.z;
+ t33 = z.z*z.z;
+
+ res.u = (1.0 - 2.0 * (t22 + t33)) * q.u
+ + (2.0 * (t12 + t03)) * q.v
+ + (2.0 * (t13 - t02)) * q.w;
+
+ res.v = (2.0 * (t12 - t03)) * q.u
+ + (1.0 - 2.0 * (t11 + t33)) * q.v
+ + (2.0 * (t01 + t23)) * q.w;
+
+ res.w = (2.0 * (t02 + t13)) * q.u
+ + (2.0 * (t23 - t01)) * q.v
+ + (1.0 - 2.0 * (t11 + t22)) * q.w;
+
+ return res;
+}
diff --git a/src/utils.h b/src/utils.h
index 2026879a..d9d0a0af 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -60,6 +60,7 @@ extern struct quaternion normalise_quaternion(struct quaternion q);
extern double quaternion_modulus(struct quaternion q);
extern struct quaternion random_quaternion(void);
extern int quaternion_valid(struct quaternion q);
+extern struct rvec quat_rot(struct rvec q, struct quaternion z);
/* --------------------------- Useful functions ----------------------------- */