Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:11:50

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Utilities/Intersection.hpp"
0013 
0014 /// @brief Helpers for planar surfaces that share the same maths
0015 namespace Acts::PlanarHelper {
0016 
0017 /// @brief Intersect a line in 3D space with a plane represented by the Hesse-Normal form
0018 /// @param linePos: Arbitrary point on the line to intersect
0019 /// @param lineDir: Direction of the line to intersect
0020 /// @param planeNorm: Normal vector of the plane
0021 /// @param offSet: Offset to move the plane along the normal vector
0022 inline Intersection3D intersectPlane(const Vector3& linePos,
0023                                      const Vector3& lineDir,
0024                                      const Vector3& planeNorm,
0025                                      const double offset) {
0026   /// Use the formula: <P, N> - C = 0
0027   ///  --> insert line equation: <A + lambda * B, N> - C = 0
0028   ///  --> lambda = (C - <A,N>)/ <N, B> */
0029   const double normDot = planeNorm.dot(lineDir);
0030   if (std::abs(normDot) < std::numeric_limits<double>::epsilon()) {
0031     return Intersection3D::invalid();
0032   }
0033   const double path = (offset - linePos.dot(planeNorm)) / normDot;
0034   return Intersection3D{linePos + path * lineDir, path,
0035                         IntersectionStatus::onSurface};
0036 }
0037 /// @brief Intersect a line in 3D space with a plane represented by the Hesse-Normal form
0038 /// @param linePos: Arbitrary point on the line to intersect
0039 /// @param lineDir: Direction of the line to intersect
0040 /// @param planeNorm: Normal vector of the plane
0041 /// @param planePoint: Point on the plane
0042 inline Intersection3D intersectPlane(const Vector3& linePos,
0043                                      const Vector3& lineDir,
0044                                      const Vector3& planeNorm,
0045                                      const Vector3& planePoint) {
0046   return intersectPlane(linePos, lineDir, planeNorm, planePoint.dot(planeNorm));
0047 }
0048 
0049 /// Intersection with a planar surface
0050 ///
0051 /// @param transform The 3D affine transform that places the surface
0052 /// @param position The starting position for the intersection
0053 /// @param direction The starting direction for the intersection
0054 ///
0055 /// @return The intersection
0056 inline Intersection3D intersect(const Transform3& transform,
0057                                 const Vector3& position,
0058                                 const Vector3& direction, double tolerance) {
0059   // Get the matrix from the transform (faster access)
0060   const auto& tMatrix = transform.matrix();
0061   const Vector3 pnormal = tMatrix.block<3, 1>(0, 2).transpose();
0062   const Vector3 pcenter = tMatrix.block<3, 1>(0, 3).transpose();
0063   // It is solvable, so go on
0064   double denom = direction.dot(pnormal);
0065   if (denom != 0.0) {
0066     // Translate that into a path
0067     double path = (pnormal.dot((pcenter - position))) / (denom);
0068     // Is valid hence either on surface or reachable
0069     IntersectionStatus status = std::abs(path) < std::abs(tolerance)
0070                                     ? IntersectionStatus::onSurface
0071                                     : IntersectionStatus::reachable;
0072     // Return the intersection
0073     return Intersection3D{(position + path * direction), path, status};
0074   }
0075   return Intersection3D::invalid();
0076 }
0077 
0078 }  // namespace Acts::PlanarHelper