IAP GITLAB

Skip to content
Snippets Groups Projects
Commit eb1c270d authored by Maximilian Reininghaus's avatar Maximilian Reininghaus :vulcan:
Browse files

added DistanceBetween() for trajectories

parent 1c27d388
No related branches found
No related tags found
No related merge requests found
...@@ -9,13 +9,20 @@ ...@@ -9,13 +9,20 @@
namespace corsika::geometry { namespace corsika::geometry {
/*! /*!
* Base class for trajectories. * Interface / base class for trajectories.
*/ */
class BaseTrajectory { class BaseTrajectory {
public: public:
//!< t for \f$ t = 0 \f$, the starting Point shall be returned. //!< for \f$ t = 0 \f$, the starting Point shall be returned.
virtual Point GetPosition(corsika::units::si::TimeType t) const = 0; virtual Point GetPosition(corsika::units::si::TimeType) const = 0;
/*!
* returns the arc length between two points of the trajectory
* parameterized by \arg t1 and \arg t2. Requires \arg t2 > \arg t1.
virtual LengthType DistanceBetween(corsika::units::si::TimeType t1,
corsika::units::si::TimeType t2) const = 0;
}; };
} // namespace corsika::geometry } // namespace corsika::geometry
......
...@@ -40,12 +40,17 @@ namespace corsika::geometry { ...@@ -40,12 +40,17 @@ namespace corsika::geometry {
, uPerp(vPerp.cross(vPar.normalized())) , uPerp(vPerp.cross(vPar.normalized()))
, radius(pvPar.norm() / abs(pOmegaC)) {} , radius(pvPar.norm() / abs(pOmegaC)) {}
Point GetPosition(corsika::units::si::TimeType t) const { Point GetPosition(corsika::units::si::TimeType t) const override {
return r0 + vPar * t + return r0 + vPar * t +
(vPerp * (cos(omegaC * t) - 1) + uPerp * sin(omegaC * t)) / omegaC; (vPerp * (cos(omegaC * t) - 1) + uPerp * sin(omegaC * t)) / omegaC;
} }
auto GetRadius() const { return radius; } auto GetRadius() const { return radius; }
LengthType DistanceBetween(corsika::units::si::TimeType t1,
corsika::units::si::TimeType t2) const override {
return (vPar + vPerp).norm() * (t2 - t1);
}
}; };
} // namespace corsika::geometry } // namespace corsika::geometry
......
...@@ -22,6 +22,12 @@ namespace corsika::geometry { ...@@ -22,6 +22,12 @@ namespace corsika::geometry {
Point GetPosition(corsika::units::si::TimeType t) const override { Point GetPosition(corsika::units::si::TimeType t) const override {
return r0 + v0 * t; return r0 + v0 * t;
} }
LengthType DistanceBetween(corsika::units::si::TimeType t1,
corsika::units::si::TimeType t2) const override {
assert(t2 >= t1);
return v0.norm() * (t2 - t1);
}
}; };
} // namespace corsika::geometry } // namespace corsika::geometry
......
...@@ -24,6 +24,10 @@ namespace corsika::geometry { ...@@ -24,6 +24,10 @@ namespace corsika::geometry {
Point GetPosition(double u) const { Point GetPosition(double u) const {
return GetPosition(fTEnd * u + fTStart * (1 - u)); return GetPosition(fTEnd * u + fTStart * (1 - u));
} }
auto GetEndpoint() const { return GetPosition(fTEnd); }
auto GetStartpoint() const { return GetPosition(fTStart); }
}; };
} // namespace corsika::geometry } // namespace corsika::geometry
......
...@@ -138,12 +138,17 @@ TEST_CASE("Trajectories") { ...@@ -138,12 +138,17 @@ TEST_CASE("Trajectories") {
BaseTrajectory const* base = &lineTrajectory; BaseTrajectory const* base = &lineTrajectory;
CHECK(lineTrajectory.GetPosition(2_s).GetCoordinates() == CHECK(lineTrajectory.GetPosition(2_s).GetCoordinates() ==
base->GetPosition(2_s).GetCoordinates()); base->GetPosition(2_s).GetCoordinates());
CHECK(base->DistanceBetween(1_s, 2_s) / 1_m == Approx(1));
} }
SECTION("Helix") { SECTION("Helix") {
Vector<SpeedType::dimension_type> const vPar( Vector<SpeedType::dimension_type> const vPar(
rootCS, {0_m / second, 0_m / second, 4_m / second}), rootCS, {0_m / second, 0_m / second, 4_m / second});
vPerp(rootCS, {1_m / second, 0_m / second, 0_m / second});
Vector<SpeedType::dimension_type> const vPerp(
rootCS, {3_m / second, 0_m / second, 0_m / second});
auto const omegaC = 2 * M_PI / 1_s; auto const omegaC = 2 * M_PI / 1_s;
Helix const helix(r0, omegaC, vPar, vPerp); Helix const helix(r0, omegaC, vPar, vPerp);
...@@ -154,12 +159,14 @@ TEST_CASE("Trajectories") { ...@@ -154,12 +159,14 @@ TEST_CASE("Trajectories") {
.magnitude() == Approx(0).margin(absMargin)); .magnitude() == Approx(0).margin(absMargin));
CHECK((helix.GetPosition(0.25_s).GetCoordinates() - CHECK((helix.GetPosition(0.25_s).GetCoordinates() -
QuantityVector<length_d>(-1_m / (2 * M_PI), -1_m / (2 * M_PI), 1_m)) QuantityVector<length_d>(-3_m / (2 * M_PI), -3_m / (2 * M_PI), 1_m))
.norm() .norm()
.magnitude() == Approx(0).margin(absMargin)); .magnitude() == Approx(0).margin(absMargin));
BaseTrajectory const* base = &helix; BaseTrajectory const* base = &helix;
CHECK(helix.GetPosition(1234_s).GetCoordinates() == CHECK(helix.GetPosition(1234_s).GetCoordinates() ==
base->GetPosition(1234_s).GetCoordinates()); base->GetPosition(1234_s).GetCoordinates());
CHECK(base->DistanceBetween(1_s, 2_s) / 1_m == Approx(5));
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment