Skip to content

Instantly share code, notes, and snippets.

@mducle
Created December 6, 2023 00:39
Show Gist options
  • Select an option

  • Save mducle/793e2073b05b4d175a6b8b00fb21b932 to your computer and use it in GitHub Desktop.

Select an option

Save mducle/793e2073b05b4d175a6b8b00fb21b932 to your computer and use it in GitHub Desktop.
Mantid solid angle bug change cylinder axis patch.
diff --git a/Framework/Geometry/src/Objects/CSGObject.cpp b/Framework/Geometry/src/Objects/CSGObject.cpp
index 286d1d953f8..eda0fa258d5 100644
--- a/Framework/Geometry/src/Objects/CSGObject.cpp
+++ b/Framework/Geometry/src/Objects/CSGObject.cpp
@@ -307,8 +307,9 @@ double cylinderSolidAngle(const V3D &observer, const V3D &centre, const V3D &axi
// axis points up the +Z axis and then rotated into their final position
// Required rotation
- constexpr V3D initial_axis(0., 0., 1.0);
- const Quat transform(initial_axis, axis);
+ constexpr V3D initial_axis(0., 1., 0.);
+ const V3D axis_direction = normalize(axis);
+ const Quat transform(initial_axis, axis_direction);
// Do the base cap which is a point at the centre and nslices points around it
constexpr double angle_step = 2 * M_PI / static_cast<double>(Cylinder::g_NSLICES);
@@ -323,13 +324,13 @@ double cylinderSolidAngle(const V3D &observer, const V3D &centre, const V3D &axi
for (int sl = 0; sl < Cylinder::g_NSLICES; ++sl) {
double x = radius * std::cos(angle_step * sl);
double y = radius * std::sin(angle_step * sl);
- V3D pt1 = V3D(x, y, z0);
- V3D pt2 = V3D(x, y, z1);
+ V3D pt1 = V3D(x, z0, -y);
+ V3D pt2 = V3D(x, z1, -y);
int vertex = (sl + 1) % Cylinder::g_NSLICES;
x = radius * std::cos(angle_step * vertex);
y = radius * std::sin(angle_step * vertex);
- V3D pt3 = V3D(x, y, z0);
- V3D pt4 = V3D(x, y, z1);
+ V3D pt3 = V3D(x, z0, -y);
+ V3D pt4 = V3D(x, z1, -y);
// Rotations
transform.rotate(pt1);
transform.rotate(pt3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment