/** * Return a local point in a cylinder shape * * @param basis a basis vector * @param alongAxis symmetry axis vector of a cylinder * @param polarAngle a polar angle (in radians) of a point in a cylinder * @param radialLength radial position of point in a cylinder * @return a local point inside the cylinder */ Kernel::V3D localPointInCylinder(const Kernel::V3D &basis, const Kernel::V3D &alongAxis, double polarAngle, double radialLength) { // Use basis to get a second perpendicular vector to define basis2 Kernel::V3D basis2; if (basis.X() == 0) { basis2.setX(1.); } else if (basis.Y() == 0) { basis2.setY(1.); } else if (basis.Z() == 0) { basis2.setZ(1.); } else { basis2.setX(-basis.Y()); basis2.setY(basis.X()); basis2.normalize(); } const Kernel::V3D basis3{basis.cross_prod(basis2)}; const Kernel::V3D localPoint{ ((basis2 * std::cos(polarAngle) + basis3 * std::sin(polarAngle)) * radialLength) + alongAxis}; return localPoint; }
/** * Calculate volume. * @return The volume. */ double MeshObject::volume() const { // Select centre of bounding box as centre point. // For each triangle calculate the signed volume of // the tetrahedron formed by the triangle and the // centre point. Then add to total. BoundingBox bb = getBoundingBox(); double cX = 0.5 * (bb.xMax() + bb.xMin()); double cY = 0.5 * (bb.yMax() + bb.yMin()); double cZ = 0.5 * (bb.zMax() + bb.zMin()); Kernel::V3D centre(cX, cY, cZ); double volumeTimesSix(0.0); Kernel::V3D vertex1, vertex2, vertex3; for (size_t i = 0; getTriangle(i, vertex1, vertex2, vertex3); ++i) { Kernel::V3D a = vertex1 - centre; Kernel::V3D b = vertex2 - centre; Kernel::V3D c = vertex3 - centre; volumeTimesSix += a.scalar_prod(b.cross_prod(c)); } return volumeTimesSix / 6.0; }