From ef1df738aeb37d2b080fdd362c5ec5033e51a4eb Mon Sep 17 00:00:00 2001
From: Raquel Alvarez Banos <raquel.alvarez.banos@gmail.com>
Date: Mon, 7 Dec 2015 17:05:43 +0000
Subject: [PATCH] Re #14684  Suggested changes

---
 .../inc/MantidDataHandling/RotateSource.h     |  5 +++-
 Framework/DataHandling/src/RotateSource.cpp   | 26 +++++--------------
 docs/source/algorithms/RotateSource-v1.rst    |  2 ++
 3 files changed, 13 insertions(+), 20 deletions(-)

diff --git a/Framework/DataHandling/inc/MantidDataHandling/RotateSource.h b/Framework/DataHandling/inc/MantidDataHandling/RotateSource.h
index 52441ab77ad..a2bb8514eb5 100644
--- a/Framework/DataHandling/inc/MantidDataHandling/RotateSource.h
+++ b/Framework/DataHandling/inc/MantidDataHandling/RotateSource.h
@@ -6,7 +6,10 @@
 namespace Mantid {
 namespace DataHandling {
 
-/** RotateSource : Moves the source by a given angle
+/** RotateSource : Moves the source by a given angle taking into account the
+  handedness. The centre of rotation is the sample's position and the rotation
+  axis (X, Y, Z) is calculated from the instrument geometry as the axis
+  perpendicular to the plane defined by the beam and "up" vectors.
 
   Copyright &copy; 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
   National Laboratory & European Spallation Source
diff --git a/Framework/DataHandling/src/RotateSource.cpp b/Framework/DataHandling/src/RotateSource.cpp
index df616df98da..171d4b0654f 100644
--- a/Framework/DataHandling/src/RotateSource.cpp
+++ b/Framework/DataHandling/src/RotateSource.cpp
@@ -31,7 +31,8 @@ void RotateSource::init() {
                   "The name of the workspace for which the new instrument "
                   "configuration will have an effect. Any other workspaces "
                   "stored in the analysis data service will be unaffected.");
-  declareProperty("Angle", 0.0, "The angle of rotation in degrees.");
+  declareProperty("Angle", 0.0, "The angle of rotation in degrees (according "
+                                "to the handedness of the coordinate system.");
 }
 
 //----------------------------------------------------------------------------------------------
@@ -70,27 +71,14 @@ void RotateSource::exec() {
 
     // Need the reference frame to decide around which axis to rotate
     auto refFrame = inst->getReferenceFrame();
-
     if (!refFrame) {
       throw std::runtime_error("Could not get a valid reference frame");
     }
 
-    auto pointingAlong = refFrame->pointingHorizontal();
-
-    // (x, y, z) -> the rotation axis
-    double x = 0.;
-    double y = 0.;
-    double z = 0.;
-
-    if (pointingAlong == X) {
-      x = 1.;
-    } else if (pointingAlong == Y) {
-      y = 1.;
-    } else if (pointingAlong == Z) {
-      z = 1.;
-    } else {
-      throw std::runtime_error("Could not get a valid rotation axis");
-    }
+    // Axis of rotation
+    auto beam = refFrame->vecPointingAlongBeam();
+    auto up = refFrame->vecPointingUp();
+    auto rotationAxis = up.cross_prod(beam);
 
     // The handedness
     auto handedness = refFrame->getHandedness();
@@ -113,7 +101,7 @@ void RotateSource::exec() {
     auto sourcePos = source->getPos() - samplePos;
 
     // The new position
-    Quat quat(angle, V3D(x, y, z));
+    Quat quat(angle, rotationAxis);
     quat.rotate(sourcePos);
     sourcePos += samplePos;
 
diff --git a/docs/source/algorithms/RotateSource-v1.rst b/docs/source/algorithms/RotateSource-v1.rst
index cd409333bfb..71c044a3307 100644
--- a/docs/source/algorithms/RotateSource-v1.rst
+++ b/docs/source/algorithms/RotateSource-v1.rst
@@ -12,6 +12,8 @@ Description
 
 This algorithm corrects the source's position by rotating it around an axis centered at the sample.
 The rotation axis is perpendicular to the plane determined by the beam direction and the *up* direction.
+The handedness of the coordinate system is considered to determine whether a positive/negative angle
+corresponds to a clockwise or counterclockwise rotation.
 
 
 Usage
-- 
GitLab