From 763a64fc497458e1920da555d8f5d4c831b21fc4 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 18 Nov 2010 13:38:46 +0100 Subject: Add divergence --- src/geometry.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/geometry.c') diff --git a/src/geometry.c b/src/geometry.c index 9db1f103..e391715c 100644 --- a/src/geometry.c +++ b/src/geometry.c @@ -76,16 +76,24 @@ static signed int locate_peak(double x, double y, double z, double k, static double excitation_error(double xl, double yl, double zl, - double ds, double k) + double ds, double k, double divergence) { double tt, al; double r; + double delta; tt = angle_between(0.0, 0.0, 1.0, xl, yl, zl+k); al = M_PI_2 - asin(-zl/ds); r = ( ds * sin(al) / sin(tt) ) - k; + delta = sqrt(2.0 * pow(ds, 2.0) * (1-cos(divergence))); + if ( divergence > 0.0 ) { + r += delta; + } else { + r -= delta; + } + return r; } @@ -99,14 +107,17 @@ static double partiality(double r1, double r2, double r) q1 = (r1 + r)/(2.0*r); q2 = (r2 + r)/(2.0*r); + /* Clamp */ if ( q1 > 1.0 ) q1 = 1.0; if ( q1 < 0.0 ) q1 = 0.0; if ( q2 > 1.0 ) q2 = 1.0; if ( q2 < 0.0 ) q2 = 0.0; + /* Convert to partiality */ p1 = 3.0*pow(q1,2.0) - 2.0*pow(q1,3.0); p2 = 3.0*pow(q2,2.0) - 2.0*pow(q2,3.0); + /* Input values may have been backwards */ p = fabs(p2 - p1); return p; @@ -182,8 +193,8 @@ struct cpeak *find_intersections(struct image *image, UnitCell *cell, if ( ds > mres ) continue; /* Outside resolution range */ /* Calculate excitation errors */ - rlow = excitation_error(xl, yl, zl, ds, klow); - rhigh = excitation_error(xl, yl, zl, ds, khigh); + rlow = excitation_error(xl, yl, zl, ds, klow, -divergence); + rhigh = excitation_error(xl, yl, zl, ds, khigh, +divergence); /* Is the reciprocal lattice point close to either extreme of * the sphere, maybe just outside the "Ewald volume"? */ -- cgit v1.2.3