Skip to content

Commit

Permalink
Merge pull request #132 from rest-for-physics/optics
Browse files Browse the repository at this point in the history
TRestPhysics::DistanceToAxis method added
  • Loading branch information
jgalan authored Feb 9, 2022
2 parents be6263a + d6521d7 commit 23065bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions source/framework/tools/inc/TRestPhysics.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ TVector3 MoveByDistanceFast(TVector3 pos, TVector3 dir, Double_t d);

TVector3 GetPlaneVectorIntersection(TVector3 pos, TVector3 dir, TVector3 n, TVector3 a);

Double_t DistanceToAxis(const TVector3& axisPoint, const TVector3& axisVector, const TVector3& point);

Double_t GetDistance(TVector3 v1, TVector3 v2);
Double_t GetDistance2(TVector3 v1, TVector3 v2);
} // namespace REST_Physics
Expand Down
11 changes: 10 additions & 1 deletion source/framework/tools/src/TRestPhysics.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ TVector3 MoveToPlane(TVector3 pos, TVector3 dir, TVector3 n, TVector3 a) {
return pos;
}

///////////////////////////////////////////////
/// \brief This method will return the distance from `point` to the straight defined by `axisPoint` and
/// `axisVector`.
///
Double_t DistanceToAxis(const TVector3& axisPoint, const TVector3& axisVector, const TVector3& point) {
TVector3 a = axisVector.Cross(axisPoint - point);
return a.Mag() / axisVector.Mag();
}

///////////////////////////////////////////////
/// \brief This method will find the intersection of the trajectory defined by the vector starting at `pos`
/// and moving in direction `dir` and the plane defined by its normal vector `n` and the point `a`. This is
Expand Down Expand Up @@ -91,4 +100,4 @@ Double_t GetDistance(TVector3 v1, TVector3 v2) { return (v2 - v1).Mag(); }
/// \brief This method returns the squared cartesian distance between vector v2 and v1.
///
Double_t GetDistance2(TVector3 v1, TVector3 v2) { return (v2 - v1).Mag2(); }
}
} // namespace REST_Physics

0 comments on commit 23065bb

Please sign in to comment.