From 8c35be50e8380709afe5f84e003f86c3e31ba578 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 13 Oct 2010 10:26:01 +0200 Subject: Matched cell must also be right-handed! --- src/cell.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/cell.c') diff --git a/src/cell.c b/src/cell.c index 78fc76e1..c07297a5 100644 --- a/src/cell.c +++ b/src/cell.c @@ -532,6 +532,24 @@ static int within_tolerance(double a, double b, double percent) } +static int right_handed(struct rvec a, struct rvec b, struct rvec c) +{ + struct rvec aCb; + double aCb_dot_c; + + /* "a" cross "b" */ + aCb.u = a.v*b.w - a.w*b.v; + aCb.v = - (a.u*b.w - a.w*b.u); + aCb.w = a.u*b.v - a.v*b.u; + + /* "a cross b" dot "c" */ + aCb_dot_c = aCb.u*c.u + aCb.v*c.v + aCb.w*c.w; + + if ( aCb_dot_c > 0.0 ) return 1; + return 0; +} + + struct cvec { struct rvec vec; float na; @@ -707,6 +725,10 @@ UnitCell *match_cell(UnitCell *cell, UnitCell *template, int verbose) /* ... it should be angle 0 ... */ if ( fabs(ang - angles[0]) > angtol ) continue; + /* Unit cell must be right-handed */ + if ( !right_handed(cand[0][i].vec, cand[1][j].vec, + cand[2][k].vec) ) continue; + fom3 = fom2 + fabs(ang - angles[0]); fom3 += LWEIGHT * (cand[0][i].fom + cand[1][j].fom + cand[2][k].fom); -- cgit v1.2.3