aboutsummaryrefslogtreecommitdiff
path: root/src/ewald.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2009-11-12 18:03:12 +0100
committerThomas White <taw@physics.org>2009-11-12 18:03:12 +0100
commitc9a551b872ae4eb16a606d46a7cf118af24f75f5 (patch)
tree9c57f03f8acb742186796e0d3a55914b61183c65 /src/ewald.c
parent2008d998a48301aef17c6247b17c4c5b92a87fdc (diff)
Loads of lattice stuff
Diffstat (limited to 'src/ewald.c')
-rw-r--r--src/ewald.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/ewald.c b/src/ewald.c
new file mode 100644
index 00000000..9d8a0450
--- /dev/null
+++ b/src/ewald.c
@@ -0,0 +1,57 @@
+/*
+ * ewald.c
+ *
+ * Calculate q-vector arrays
+ *
+ * (c) 2007-2009 Thomas White <thomas.white@desy.de>
+ *
+ * pattern_sim - Simulate diffraction patterns from small crystals
+ *
+ */
+
+
+#include <stdlib.h>
+#include <math.h>
+#include <stdio.h>
+
+#include "image.h"
+#include "utils.h"
+#include "cell.h"
+
+
+void get_ewald(struct image *image)
+{
+ int x, y;
+ double k; /* Wavenumber */
+
+ k = 1/image->lambda;
+
+ image->qvecs = malloc(image->width * image->height
+ * sizeof(struct threevec));
+
+ for ( x=0; x<image->width; x++ ) {
+ for ( y=0; y<image->height; y++ ) {
+
+ double rx, ry, r;
+ double twothetax, twothetay, twotheta;
+ double qx, qy, qz;
+
+ rx = ((double)x - image->x_centre) / image->resolution;
+ ry = ((double)y - image->y_centre) / image->resolution;
+ r = sqrt(pow(rx, 2.0) + pow(ry, 2.0));
+
+ twothetax = atan2(rx, image->camera_len);
+ twothetay = atan2(ry, image->camera_len);
+ twotheta = atan2(r, image->camera_len);
+
+ qx = k * sin(twothetax);
+ qy = k * sin(twothetay);
+ qz = k - k * cos(twotheta);
+
+ image->qvecs[x + image->width*y].u = qx;
+ image->qvecs[x + image->width*y].v = qy;
+ image->qvecs[x + image->width*y].w = qz;
+
+ }
+ }
+}