Import Geant4 11.4.0 source tree

This commit is contained in:
Gabriele Cosmo
2025-12-05 08:54:02 +01:00
parent a499fb82e9
commit b4a16de652
6484 changed files with 232674 additions and 221097 deletions
+221 -165
View File
@@ -27,10 +27,10 @@
//
// Class description:
//
// A collection of utilities which can be helpfull for a wide range
// A collection of utilities which can be helpful for a wide range
// of geometry-related tasks
// 10.10.2016, E.Tcherniaev: Initial version.
// Author: Evgueni Tcherniaev (CERN), 10.10.2016
// --------------------------------------------------------------------
#ifndef G4GEOMTOOLS_HH
#define G4GEOMTOOLS_HH
@@ -42,191 +42,247 @@
using G4TwoVectorList = std::vector<G4TwoVector>;
using G4ThreeVectorList = std::vector<G4ThreeVector>;
/**
* @brief G4GeomTools is a collecting utilities which can be helpful
* for a wide range of geometry-related tasks.
*/
class G4GeomTools
{
public:
// ==================================================================
// 2D Utilities
// ------------------------------------------------------------------
// ==================================================================
// 2D Utilities
// ------------------------------------------------------------------
static G4double TriangleArea(G4double Ax, G4double Ay,
G4double Bx, G4double By,
G4double Cx, G4double Cy);
/**
* Functions to calculate the area of 2D triangle, returned value is
* positive if the vertices of the triangle are given in anticlockwise
* order, otherwise it is negative.
*/
static G4double TriangleArea(G4double Ax, G4double Ay,
G4double Bx, G4double By,
G4double Cx, G4double Cy);
static G4double TriangleArea(const G4TwoVector& A,
const G4TwoVector& B,
const G4TwoVector& C);
static G4double TriangleArea(const G4TwoVector& A,
const G4TwoVector& B,
const G4TwoVector& C);
// Calculate area of 2D triangle, return value is positive if
// vertices of the triangle are given in anticlockwise order,
// otherwise it is negative
/**
* Calculates the area of a 2D quadrilateral, returned value is positive if
* the vertices of the quadrilateral are given in anticlockwise order,
* otherwise it is negative.
*/
static G4double QuadArea(const G4TwoVector& A,
const G4TwoVector& B,
const G4TwoVector& C,
const G4TwoVector& D);
static G4double QuadArea(const G4TwoVector& A,
const G4TwoVector& B,
const G4TwoVector& C,
const G4TwoVector& D);
// Calculate area of 2D quadrilateral, return value is positive if
// vertices of the quadrilateral are given in anticlockwise order,
// otherwise it is negative
/**
* Calculates the area of a 2D polygon, returned value is positive if
* the vertices of the polygon are defined in anticlockwise order,
* otherwise it is negative.
*/
static G4double PolygonArea(const G4TwoVectorList& polygon);
static G4double PolygonArea(const G4TwoVectorList& polygon);
// Calculate area of 2D polygon, return value is positive if
// vertices of the polygon are defined in anticlockwise order,
// otherwise it is negative
/**
* Decides if a point (Px,Py) is inside the triangle (Ax,Ay)(Bx,By)(Cx,Cy).
*/
static G4bool PointInTriangle(G4double Px, G4double Py,
G4double Ax, G4double Ay,
G4double Bx, G4double By,
G4double Cx, G4double Cy);
static G4bool PointInTriangle(G4double Px, G4double Py,
G4double Ax, G4double Ay,
G4double Bx, G4double By,
G4double Cx, G4double Cy);
// Decide if point (Px,Py) is inside triangle (Ax,Ay)(Bx,By)(Cx,Cy)
/**
* Decides if a point P is inside the triangle ABC.
*/
static G4bool PointInTriangle(const G4TwoVector& P,
const G4TwoVector& A,
const G4TwoVector& B,
const G4TwoVector& C);
static G4bool PointInTriangle(const G4TwoVector& P,
const G4TwoVector& A,
const G4TwoVector& B,
const G4TwoVector& C);
// Decide if point P is inside triangle ABC
/**
* Decides if a point P is inside the 'Polygon'.
*/
static G4bool PointInPolygon(const G4TwoVector& P,
const G4TwoVectorList& Polygon);
static G4bool PointInPolygon(const G4TwoVector& P,
const G4TwoVectorList& Polygon);
// Decide if point P is inside Polygon
/**
* Decides if a 2D 'polygon' is convex, i.e. if all internal angles are
* less than pi.
*/
static G4bool IsConvex(const G4TwoVectorList& polygon);
static G4bool IsConvex(const G4TwoVectorList& polygon);
// Decide if 2D polygon is convex, i.e. all internal angles are
// less than pi
/**
* Simple implementation of "ear clipping" algorithm for triangulation
* of a simple contour/polygon, it places results in a std::vector as
* triplets of vertices. If triangulation is successful the function
* returns true, otherwise false.
*/
static G4bool TriangulatePolygon(const G4TwoVectorList& polygon,
std::vector<G4int>& result);
static G4bool TriangulatePolygon(const G4TwoVectorList& polygon,
G4TwoVectorList& result);
/**
* Same using the function above and returning as 'result' a list
* of triangles.
*/
static G4bool TriangulatePolygon(const G4TwoVectorList& polygon,
G4TwoVectorList& result);
static G4bool TriangulatePolygon(const G4TwoVectorList& polygon,
std::vector<G4int>& result);
// Simple implementation of "ear clipping" algorithm for
// triangulation of a simple contour/polygon, it places results
// in a std::vector as triplets of vertices. If triangulation
// is sucsessfull then the function returns true, otherwise false
/**
* Removes collinear and coincident points from a 2D 'polygon'.
* Indices of removed points are available in 'iout'.
* Allows to specify a 'tolerance'.
*/
static void RemoveRedundantVertices(G4TwoVectorList& polygon,
std::vector<G4int>& iout,
G4double tolerance = 0.0);
static void RemoveRedundantVertices(G4TwoVectorList& polygon,
std::vector<G4int>& iout,
G4double tolerance = 0.0);
// Remove collinear and coincident points from 2D polygon.
// Indices of removed points are available in iout.
static G4bool DiskExtent(G4double rmin, G4double rmax,
G4double startPhi, G4double delPhi,
G4TwoVector& pmin, G4TwoVector& pmax);
// Calculate bounding rectangle of a disk sector,
// it returns false if input parameters do not meet the following:
// rmin >= 0
// rmax > rmin + kCarTolerance
// delPhi > 0 + kCarTolerance
static void DiskExtent(G4double rmin, G4double rmax,
G4double sinPhiStart, G4double cosPhiStart,
G4double sinPhiEnd, G4double cosPhiEnd,
G4TwoVector& pmin, G4TwoVector& pmax);
// Calculate bounding rectangle of a disk sector,
// faster version without check of parameters
static G4double EllipsePerimeter(G4double a,
G4double b);
// Compute the circumference (perimeter) of an ellipse
static G4double EllipticConeLateralArea(G4double a,
G4double b,
G4double h);
// Compute the lateral surface area of an elliptic cone
// ==================================================================
// 3D Utilities
// ------------------------------------------------------------------
static G4ThreeVector TriangleAreaNormal(const G4ThreeVector& A,
const G4ThreeVector& B,
const G4ThreeVector& C);
// Find the normal to the plane of 3D triangle ABC,
// length of the normal is equal to the area of the triangle
static G4ThreeVector QuadAreaNormal(const G4ThreeVector& A,
const G4ThreeVector& B,
const G4ThreeVector& C,
const G4ThreeVector& D);
// Find normal to the plane of 3D quadrilateral ABCD,
// length of the normal is equal to the area of the quadrilateral
static G4ThreeVector PolygonAreaNormal(const G4ThreeVectorList& polygon);
// Find normal to the plane of 3D polygon
// length of the normal is equal to the area of the polygon
/*
static G4bool IsPlanar(const G4ThreeVector& A,
const G4ThreeVector& B,
const G4ThreeVector& C,
const G4ThreeVector& D);
// Decide if 3D quadrilateral ABCD is planar
static G4bool IsPlanar(const G4ThreeVectorList& polygon
const G4ThreeVector& normal);
// Decide if 3D polygon is planar
*/
static G4double DistancePointSegment(const G4ThreeVector& P,
const G4ThreeVector& A,
const G4ThreeVector& B);
// Calculate distance between point P and line segment AB in 3D
static G4ThreeVector ClosestPointOnSegment(const G4ThreeVector& P,
const G4ThreeVector& A,
const G4ThreeVector& B);
// Find point on 3D line segment AB closest to point P
static G4ThreeVector ClosestPointOnTriangle(const G4ThreeVector& P,
const G4ThreeVector& A,
const G4ThreeVector& B,
const G4ThreeVector& C);
// Find point on 3D triangle ABC closest to point P
static G4bool SphereExtent(G4double rmin, G4double rmax,
G4double startTheta, G4double delTheta,
/**
* Calculates the bounding rectangle of a disk sector. It returns false
* if the input parameters do not meet the following criteria:
* rmin >= 0
* rmax > rmin + kCarTolerance
* delPhi > 0 + kCarTolerance.
*/
static G4bool DiskExtent(G4double rmin, G4double rmax,
G4double startPhi, G4double delPhi,
G4ThreeVector& pmin, G4ThreeVector& pmax);
// Calculate bounding box of a spherical sector,
// it returns false if input parameters do not meet the following:
// rmin >= 0
// rmax > rmin + kCarTolerance
// startTheta >= 0 && <= pi;
// delTheta > 0 + kCarTolerance
// delPhi > 0 + kCarTolerance
G4TwoVector& pmin, G4TwoVector& pmax);
static G4double HypeStereo(G4double r0, // radius at z = 0
G4double r, // radius at z = h
G4double h);
// Calculate hyperbolic surface stereo
// Stereo is a half angle at the intersection point of the two
// lines in the tangent plane cross section
/**
* Calculates the bounding rectangle of a disk sector.
* Faster version without check of parameters.
*/
static void DiskExtent(G4double rmin, G4double rmax,
G4double sinPhiStart, G4double cosPhiStart,
G4double sinPhiEnd, G4double cosPhiEnd,
G4TwoVector& pmin, G4TwoVector& pmax);
static void TwistedTubeBoundingTrap(G4double twistAng, // twist angle
G4double endInnerRad, // inner radius at z = halfZ
G4double endOuterRad, // outer radius at z = halfZ
G4double dPhi, // delta phi
G4TwoVectorList& vertices); // corners of generic trap
// Find XY-coordinates of the corners of the generic trap
// that bounds specified twisted tube
/**
* Computes the circumference (perimeter) of an ellipse.
*/
static G4double EllipsePerimeter(G4double a,
G4double b);
static G4double HyperboloidSurfaceArea(G4double dphi, // delta phi
G4double r0, // radius at z = 0
G4double tanstereo, // tan(stereo)
G4double zmin,
G4double zmax);
// Calculate surface area of the hyperboloid between zmin and zmax
/**
* Computes the lateral surface area of an elliptic cone.
*/
static G4double EllipticConeLateralArea(G4double a,
G4double b,
G4double h);
// ==================================================================
// 3D Utilities
// ------------------------------------------------------------------
/**
* Finds the normal to the plane of a 3D triangle ABC;
* the length of the normal is equal to the area of the triangle.
*/
static G4ThreeVector TriangleAreaNormal(const G4ThreeVector& A,
const G4ThreeVector& B,
const G4ThreeVector& C);
/**
* Finds the normal to the plane of a 3D quadrilateral ABCD;
* the length of the normal is equal to the area of the quadrilateral.
*/
static G4ThreeVector QuadAreaNormal(const G4ThreeVector& A,
const G4ThreeVector& B,
const G4ThreeVector& C,
const G4ThreeVector& D);
/**
* Finds the normal to the plane of a 3D polygon; the length of the
* normal is equal to the area of the polygon.
*/
static G4ThreeVector PolygonAreaNormal(const G4ThreeVectorList& polygon);
/**
* Calculates the distance between a point 'P' and line segment AB in 3D.
*/
static G4double DistancePointSegment(const G4ThreeVector& P,
const G4ThreeVector& A,
const G4ThreeVector& B);
/**
* Finds a point on a 3D line segment AB closest to point 'P'.
*/
static G4ThreeVector ClosestPointOnSegment(const G4ThreeVector& P,
const G4ThreeVector& A,
const G4ThreeVector& B);
/**
* Finds a point on a 3D triangle ABC closest to point 'P'.
*/
static G4ThreeVector ClosestPointOnTriangle(const G4ThreeVector& P,
const G4ThreeVector& A,
const G4ThreeVector& B,
const G4ThreeVector& C);
/**
* Calculates the bounding box of a spherical sector,
* @returns false if input parameters do not meet the following criteria:
* rmin >= 0
* rmax > rmin + kCarTolerance
* startTheta >= 0 && <= pi;
* delTheta > 0 + kCarTolerance
* delPhi > 0 + kCarTolerance.
*/
static G4bool SphereExtent(G4double rmin, G4double rmax,
G4double startTheta, G4double delTheta,
G4double startPhi, G4double delPhi,
G4ThreeVector& pmin, G4ThreeVector& pmax);
/**
* Calculates the hyperbolic surface stereo. Stereo is a half angle at the
* intersection point of the two lines in the tangent plane cross-section.
*/
static G4double HypeStereo(G4double r0, // radius at z = 0
G4double r, // radius at z = h
G4double h);
/**
* Finds the XY-coordinates of the corners of a generic trap that bounds
* specified twisted tube.
* @param[in] twistAng The twist angle.
* @param[in] endInnerRad The inner radius at z = halfZ.
* @param[in] endOuterRad The outer radius at z = halfZ.
* @param[in] dPhi Delta phi.
* @param[in] vertices The corners of the generic trap.
*/
static void TwistedTubeBoundingTrap(G4double twistAng,
G4double endInnerRad,
G4double endOuterRad,
G4double dPhi,
G4TwoVectorList& vertices);
/**
* Calculate surface area of the hyperboloid between 'zmin' and 'zmax'.
* @param[in] dphi Delta phi.
* @param[in] r0 The radius at z = 0.
* @param[in] tanstereo The tangent of the stereo angle.
* @param[in] zmin Minimum Z.
* @param[in] zmax Maximum Z.
*/
static G4double HyperboloidSurfaceArea(G4double dphi,
G4double r0,
G4double tanstereo,
G4double zmin,
G4double zmax);
private:
static G4bool CheckSnip(const G4TwoVectorList& contour,
G4int a, G4int b, G4int c,
G4int n, const G4int* V);
// Helper function for TriangulatePolygon()
/**
* Helper function for use by TriangulatePolygon().
*/
static G4bool CheckSnip(const G4TwoVectorList& contour,
G4int a, G4int b, G4int c,
G4int n, const G4int* V);
static G4double comp_ellint_2(G4double e);
// Complete Elliptic Integral of the Second Kind
/**
* Complete Elliptic Integral of the Second Kind.
*/
static G4double comp_ellint_2(G4double e);
};
#endif // G4GEOMTOOLS_HH
#endif