10#include <boost/math/special_functions/pow.hpp>
24 double radialLength) {
29 }
else if (basis.
Y() == 0) {
31 }
else if (basis.
Z() == 0) {
34 basis2.
setX(-basis.
Y());
35 basis2.
setY(basis.
X());
39 const Kernel::V3D localPoint{((basis2 * std::cos(polarAngle) + basis3 * std::sin(polarAngle)) * radialLength) +
55 const Kernel::V3D basis1{geometry.leftFrontTop - geometry.leftFrontBottom};
56 const Kernel::V3D basis2{geometry.leftBackBottom - geometry.leftFrontBottom};
57 const Kernel::V3D basis3{geometry.rightFrontBottom - geometry.leftFrontBottom};
58 return geometry.leftFrontBottom + (basis1 * r1 + basis2 * r2 + basis3 * r3);
72 const double polar{2. * M_PI * r1};
74 const double r{geometry.radius * std::sqrt(r2)};
75 const double z{geometry.height * r3};
78 return localPoint + geometry.centreOfBottomBase;
92 const double polar{2. * M_PI * r1};
95 const double c1 = geometry.innerRadius * geometry.innerRadius;
96 const double c2 = geometry.radius * geometry.radius;
97 const double r{std::sqrt(c1 + (c2 - c1) * r2)};
98 const double z{geometry.height * r3};
101 return localPoint + geometry.centreOfBottomBase;
115 const double azimuthal{2. * M_PI * r1};
117 const double polar{std::acos(2. * r2 - 1.)};
118 const double r{r3 * geometry.radius};
119 const double x{r * std::cos(azimuthal) * std::sin(polar)};
120 const double y{r * std::sin(azimuthal) * std::sin(polar)};
121 const double z{r * std::cos(polar)};
133 size_t maxAttempts) {
134 return bounded(
object, rng,
object.getBoundingBox(), maxAttempts);
147 boost::optional<Kernel::V3D> point{boost::none};
149 throw std::invalid_argument(
"Invalid bounding box. Cannot generate random point.");
151 for (
size_t attempts{0}; attempts < maxAttempts; ++attempts) {
156 if (
object.isValid(pt)) {
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
Kernel::V3D generatePointInside(double r1, double r2, double r3) const
Generate a random point within the box.
bool isNull() const
Is this a default constructed box?
IObject : Interface for geometry objects.
SphereGeometry sphereGeometry() const
CylinderGeometry cylinderGeometry() const
CuboidGeometry cuboidGeometry() const
HollowCylinderGeometry hollowCylinderGeometry() const
Defines a 1D pseudo-random number generator, i.e.
virtual double nextValue()=0
Return the next double in the sequence.
constexpr double X() const noexcept
Get x.
double normalize()
Make a normalized vector (return norm value)
constexpr V3D cross_prod(const V3D &v) const noexcept
Cross product (this * argument)
constexpr double Y() const noexcept
Get y.
void setZ(const double zz) noexcept
Set is z position.
void setX(const double xx) noexcept
Set is x position.
void setY(const double yy) noexcept
Set is y position.
constexpr double Z() const noexcept
Get z.
MANTID_GEOMETRY_DLL Kernel::V3D inCylinder(const detail::ShapeInfo &shapeInfo, Kernel::PseudoRandomNumberGenerator &rng)
Return a random point in cylinder.
MANTID_GEOMETRY_DLL Kernel::V3D inCuboid(const detail::ShapeInfo &shapeInfo, Kernel::PseudoRandomNumberGenerator &rng)
Return a random point in a cuboid shape.
MANTID_GEOMETRY_DLL Kernel::V3D inSphere(const detail::ShapeInfo &shapeInfo, Kernel::PseudoRandomNumberGenerator &rng)
Return a random point in sphere.
MANTID_GEOMETRY_DLL Kernel::V3D inHollowCylinder(const detail::ShapeInfo &shapeInfo, Kernel::PseudoRandomNumberGenerator &rng)
Return a random point in a hollow cylinder.
MANTID_GEOMETRY_DLL Kernel::V3D localPointInCylinder(const Kernel::V3D &basis, const Kernel::V3D &alongAxis, double polarAngle, double radialLength)
Return a local point in a cylinder shape.
MANTID_GEOMETRY_DLL boost::optional< Kernel::V3D > inGenericShape(const IObject &object, Kernel::PseudoRandomNumberGenerator &rng, size_t maxAttempts)
Return a random point in a generic shape.
boost::optional< Kernel::V3D > bounded(const detail::ShapeInfo &shapeInfo, Kernel::PseudoRandomNumberGenerator &rng, const BoundingBox &box, size_t maxAttempts)
Return a random point in a known shape restricted by a bounding box.