Geometry of Shape¶
What is it?¶
In Mantid we use constructive solid geometry (CSG) to describe the shape of an object. This involves the creation of more complex shapes by the union, complement or intersection of simple primitive surfaces.
Why did we use CSG¶
Defining our object shape using CSG was selected for a number of reasons:
Using Surfaces based on mathematical equations rather than meshes of vertices give much better accuracy when tracking the interaction of particles through objects.
Scientists think in the shape of objects this way, for example if they have a sample that is a sphere radius 0.03m with a conical extrusion on top then that is exactly how they describe it in CSG. Otherwise they would need to be able to describe the co-ordinates for each vertex of the surface.
What shapes can be constructed¶
Mantid has direct support for creating various shapes directly, including
Sphere
Infinite Cylinder
Cylinder (finite height)
Slice of cylinder ring
Infinite Plane
Cuboid
Infinite Cone
Some of these shapes are infinite surfaces (the infinite plane, cone and cylinder) these are therefore not very useful on there own, but in combination with other shapes they can be capped as required.
For example if you cap and infinite Cylinder with two infinite planes you get a finite capped cylinder. This is in fact how the Cylinder shape is defined internally within Mantid.
For more on this see HowToDefineGeometricShape.
Calculating intersections between shapes¶
Intersection of a line and a cylinder¶
The line in Mantid is the equivalent of a ray in Math, and the cylinder here is referring to a cylindrical surface. The current intersection solver implemented in Mantid is using the parametrization method where a quadratic equation is solved to find the intersection point. This section will provide an in-depth derivation on how the final parameterization is formed, which is directly used in the source code.
For an arbitrary cylindrical surface, it can be uniquely defined by its radius
where
The parameterization of a random cylindrical surface in 3D can be complicated, but there is a simple mathematical expression when some special reference frame is used. More specifically, when the symmetry axis is one of the axis of the reference frame (using z-axis as an example here), a cylindrical surface can be expressed as:
The easiest way to solve for the intersection point is to plug the line parameterization
into the equation above.
However, this is not possible at the moment because the two equations are not in
the same reference frame.
Therefore, we need to convert the line parameterization parameters into the special
cylindrical surface reference framework before we can solve for

The figure above shows one of the special reference frame that can make the math
a lot easier to handle.
In this reference frame, the origin is a random point along the symmetry axis of
the cylinder surface, and the symmetry axis is the z-axis.
The starting point of the line,
Notice that
Since
Notice that all the values on the left-hand are all in the special reference frame whereas the values on the right-hand are in the general/global reference frame.
Another thing worth mentioning here is that the expression above is assuming the special reference frame and the original reference frame share the same origin, which is true in most cases in mantid. However, if they are not the same, we need to take into consideration of the rigid-body shift due to change of origin, which can be easily done by:
where
As for the covariances of the direction vector, the z component is relatively easy,
Finding the x component takes a little bit extra efforts. The x-axis of the special reference frame can be expressed as a unit vector:
Therefore,
Since direction vector is a unit vector, we can easily find
Now we can plug the line parameterization into the cylindrical surface equation
to get the interception by solving for
For a standard quadratic equation,
and
and
Category: Concepts