Attitude of rotation, Python to C++
Hi Folks, Just started moving code from Python to C++ - and seeing a 40x speedup which is nice - however I noticed something odd. scitbx.matrix.col.rotate(axis, angle) has the reversed attitude to scitbx::vec3<double>.rotate(scitbx::vec3<double>, double angle) viz: this python code s = (self._ub * hkl).rotate(self._axis, angle) q = (s + self._s0).normalize() # check if diffracted ray parallel to detector face q_dot_n = q.dot(detector_normal) if q_dot_n == 0: continue r = (q * distance / q_dot_n) - self._detector_origin x = r.dot(self._detector_fast) y = r.dot(self._detector_slow) if x < self._limits[0] or y < self._limits[2]: continue if x > self._limits[1] or y > self._limits[3]: continue observed_reflection_positions.append((hkl, x, y, angle)) gives the same result as scitbx::vec3<double> s, q, r; double x, y, q_dot_n; /* this is rather weird - the attitude of rotation is back to front in the c++ code */ s = (ub * hkl).rotate(axis, - angle); q = (s + s0).normalize(); q_dot_n = q * normal; if (q_dot_n == 0) return false; r = (q * distance / q_dot_n) - origin; x = r * fast; y = r * slow; if (x < limits[0]) return false; if (y < limits[2]) return false; if (x > limits[1]) return false; if (y > limits[3]) return false; prediction[0] = x; prediction[1] = y; where I had to use -angle. Code is linked into same routines - used identically. With -angle I get numerically identical results (which is nice) Anyone got any clues on this one? Thanks, Graeme -- This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail. Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd. Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message. Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom
Hi Graeme,
Ouch... this is an unfortunate mixup. I derived the C++ code from cgkit
many years ago without checking. I'm changing it now to be compatible with
http://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula
and the Python code in scitbx.matrix.
cctbx rev. 14644, labelit rev. 1923.
Thanks a lot for pointing out the inconsistency.
Ralf
On Thu, Jan 12, 2012 at 4:03 AM,
Hi Folks,
Just started moving code from Python to C++ - and seeing a 40x speedup which is nice - however I noticed something odd.
scitbx.matrix.col.rotate(axis, angle)
has the reversed attitude to
scitbx::vec3<double>.rotate(scitbx::vec3<double>, double angle)
viz:
this python code
s = (self._ub * hkl).rotate(self._axis, angle) q = (s + self._s0).normalize()
# check if diffracted ray parallel to detector face
q_dot_n = q.dot(detector_normal)
if q_dot_n == 0: continue
r = (q * distance / q_dot_n) - self._detector_origin
x = r.dot(self._detector_fast) y = r.dot(self._detector_slow)
if x < self._limits[0] or y < self._limits[2]: continue if x > self._limits[1] or y > self._limits[3]: continue
observed_reflection_positions.append((hkl, x, y, angle))
gives the same result as
scitbx::vec3<double> s, q, r; double x, y, q_dot_n;
/* this is rather weird - the attitude of rotation is back to front in the c++ code */
s = (ub * hkl).rotate(axis, - angle); q = (s + s0).normalize(); q_dot_n = q * normal;
if (q_dot_n == 0) return false;
r = (q * distance / q_dot_n) - origin;
x = r * fast; y = r * slow;
if (x < limits[0]) return false; if (y < limits[2]) return false; if (x > limits[1]) return false; if (y > limits[3]) return false;
prediction[0] = x; prediction[1] = y;
where I had to use -angle. Code is linked into same routines - used identically. With -angle I get numerically identical results (which is nice)
Anyone got any clues on this one?
Thanks,
Graeme -- This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail. Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd. Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message. Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom
_______________________________________________ cctbxbb mailing list [email protected] http://phenix-online.org/mailman/listinfo/cctbxbb
Thanks Ralf, good to know the difference was real.
It has to be said, spotting this was much easier where transferring code from Python to C++ was not far from trivial, which is a massive help!
Thanks,
Graeme
________________________________
From: [email protected] [[email protected]] on behalf of Ralf Grosse-Kunstleve [[email protected]]
Sent: 13 January 2012 06:43
To: cctbx mailing list
Subject: Re: [cctbxbb] Attitude of rotation, Python to C++
Hi Graeme,
Ouch... this is an unfortunate mixup. I derived the C++ code from cgkit many years ago without checking. I'm changing it now to be compatible with http://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula
and the Python code in scitbx.matrix.
cctbx rev. 14644, labelit rev. 1923.
Thanks a lot for pointing out the inconsistency.
Ralf
On Thu, Jan 12, 2012 at 4:03 AM,
participants (2)
-
Graeme.Winter@Diamond.ac.uk
-
Ralf Grosse-Kunstleve