19std::vector<double>
getVertices(
const std::vector<Kernel::V3D> &vertices) {
20 std::vector<double> points;
21 size_t nPoints = vertices.size();
23 points.resize(
static_cast<std::size_t
>(nPoints) * 3);
24 for (
size_t i = 0; i < nPoints; ++i) {
25 const auto &pnt = vertices[i];
26 points[i * 3] = pnt.X();
27 points[i * 3 + 1] = pnt.Y();
28 points[i * 3 + 2] = pnt.Z();
53 const double modao = ao.
norm();
54 const double modbo = bo.
norm();
55 const double modco = co.
norm();
60 const double denom = modao * modbo * modco + modco * aobo + modbo * aoco + modao * boco;
62 return 2.0 * atan2(scalTripProd, denom);
94 auto dot01 = e0.scalar_prod(e1);
95 auto dot02 = e0.scalar_prod(e2);
96 auto dot11 = e1.scalar_prod(e1);
97 auto dot12 = e1.scalar_prod(e2);
110 auto invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
111 auto u = (dot11 * dot02 - dot01 * dot12) * invDenom;
112 auto v = (dot00 * dot12 - dot01 * dot02) * invDenom;
115 return (u >= 0) && (v >= 0) && (u + v <= 1);
151 auto edge1 = v2 - v1;
152 auto edge2 = v3 - v1;
156 const double EPSILON = 0.0000001 * edge1.norm();
162 auto u = f * (s.scalar_prod(h));
163 if (u < 0.0 || u > 1.0)
168 if (v < 0.0 || u + v > 1.0)
173 auto t = f * edge2.scalar_prod(q);
180 const auto scalar_prod = normalDirection.
scalar_prod(direction);
181 if (scalar_prod > 0.) {
183 }
else if (scalar_prod < 0.) {
186 throw std::domain_error(
"Track is in same direction as surface");
195 if (nVertices >= std::numeric_limits<uint32_t>::max()) {
196 throw std::invalid_argument(
"Too many vertices (" +
std::to_string(nVertices) +
197 "). MeshObject cannot have more than 2^32 vertices.");
210 static const double MinThickness = 0.001;
211 double minX, maxX, minY, maxY, minZ, maxZ;
212 minX = minY = minZ = std::numeric_limits<double>::max();
213 maxX = maxY = maxZ = std::numeric_limits<double>::lowest();
216 for (
const auto &vertex : vertices) {
217 auto vx = vertex.X();
218 auto vy = vertex.Y();
219 auto vz = vertex.Z();
221 minX = std::min(minX, vx);
222 maxX = std::max(maxX, vx);
223 minY = std::min(minY, vy);
224 maxY = std::max(maxY, vy);
225 minZ = std::min(minZ, vz);
226 maxZ = std::max(maxZ, vz);
229 maxX += MinThickness;
231 maxY += MinThickness;
233 maxZ += MinThickness;
236 cacheBB =
BoundingBox(maxX, maxY, maxZ, minX, minY, minZ);
256 double &zmax,
double &xmin,
double &ymin,
double &zmin) {
const double EPSILON(1.0E-10)
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
bool isNull() const
Is this a default constructed box?
constexpr double scalar_prod(const V3D &v) const noexcept
Calculates the cross product.
constexpr V3D cross_prod(const V3D &v) const noexcept
Cross product (this * argument)
double norm() const noexcept
MeshObjectCommon : Performs functions common to 3D and 2D closed meshes.
MANTID_GEOMETRY_DLL bool rayIntersectsTriangle(const Kernel::V3D &start, const Kernel::V3D &direction, const Kernel::V3D &v1, const Kernel::V3D &v2, const Kernel::V3D &v3, Kernel::V3D &intersection, TrackDirection &entryExit)
Get intersection points and their in out directions on the given ray.
MANTID_GEOMETRY_DLL void checkVertexLimit(size_t nVertices)
MANTID_GEOMETRY_DLL std::vector< double > getVertices(const std::vector< Kernel::V3D > &vertices)
getVertices converts vector Kernel::V3D to vector doubles.
MANTID_GEOMETRY_DLL double getTriangleSolidAngle(const Kernel::V3D &a, const Kernel::V3D &b, const Kernel::V3D &c, const Kernel::V3D &observer)
Find the solid angle of a triangle defined by vectors a,b,c from point "observer".
MANTID_GEOMETRY_DLL const BoundingBox & getBoundingBox(const std::vector< Kernel::V3D > &vertices, BoundingBox &cacheBB)
Takes input vertices and calculates bounding box.
MANTID_GEOMETRY_DLL bool isOnTriangle(const Kernel::V3D &point, const Kernel::V3D &v1, const Kernel::V3D &v2, const Kernel::V3D &v3)
isOnTriangle
bool MANTID_GEOMETRY_DLL intersection(const ConvexPolygon &P, const ConvexPolygon &Q, ConvexPolygon &out)
Compute the instersection of two convex polygons.
std::string to_string(const wide_integer< Bits, Signed > &n)