aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/detgeom.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2021-01-08 16:10:26 +0100
committerThomas White <taw@physics.org>2021-01-08 16:10:26 +0100
commit708590dd4bfac92bde90d9762f413c7496afbddf (patch)
treeb5b097a39f6104aadf1219a0de62750444db538f /libcrystfel/src/detgeom.c
parent3410f0a68f889bc6d94f52904abe5a68ba2fe19a (diff)
detgeom_transform_coords: Avoid using trigonometric functions
Diffstat (limited to 'libcrystfel/src/detgeom.c')
-rw-r--r--libcrystfel/src/detgeom.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/libcrystfel/src/detgeom.c b/libcrystfel/src/detgeom.c
index 05a618bc..58b14631 100644
--- a/libcrystfel/src/detgeom.c
+++ b/libcrystfel/src/detgeom.c
@@ -47,22 +47,19 @@ void detgeom_transform_coords(struct detgeom_panel *p,
double wavelength,
double *r)
{
- double ctt, twotheta;
double xs, ys, zs;
- double az;
+ double fac;
- /* Calculate 3D position of given position, in m */
- xs = (p->cnx + fs*p->fsx + ss*p->ssx) * p->pixel_pitch;
- ys = (p->cny + fs*p->fsy + ss*p->ssy) * p->pixel_pitch;
- zs = (p->cnz + fs*p->fsz + ss*p->ssz) * p->pixel_pitch;
+ /* Calculate 3D position of given position, in pixels */
+ xs = p->cnx + fs*p->fsx + ss*p->ssx;
+ ys = p->cny + fs*p->fsy + ss*p->ssy;
+ zs = p->cnz + fs*p->fsz + ss*p->ssz;
- ctt = zs/sqrt(xs*xs + ys*ys + zs*zs);
- twotheta = acos(ctt);
- az = atan2(ys, xs);
+ fac = wavelength * sqrt(xs*xs + ys*ys + zs*zs);
- r[0] = sin(twotheta)*cos(az) / wavelength;
- r[1] = sin(twotheta)*sin(az) / wavelength;
- r[2] = (ctt - 1.0) / wavelength;
+ r[0] = xs / fac;
+ r[1] = ys / fac;
+ r[2] = zs / fac - 1.0/wavelength;
}