diff --git a/Framework/Geometry/CoordinateSystem.cc b/Framework/Geometry/CoordinateSystem.cc index db0dea292aa5757f636c374da7d2c8155e34287f..b74808cdbaa115ad5b1e1b04dd7d9379b3f5d74c 100644 --- a/Framework/Geometry/CoordinateSystem.cc +++ b/Framework/Geometry/CoordinateSystem.cc @@ -2,14 +2,21 @@ using namespace corsika::geometry; -EigenTransform CoordinateSystem::GetTransformation(CoordinateSystem const& c1, - CoordinateSystem const& c2) { - CoordinateSystem const* a{&c1}; - CoordinateSystem const* b{&c2}; +/** + * returns the transformation matrix necessary to transform primitives with coordinates + * in \a pFrom to \a pTo, e.g. + * \f$ \vec{v}^{\text{(to)}} = \mathcal{M} \vec{v}^{\text{(from)}} \f$ + * (\f$ \vec{v}^{(.)} \f$ denotes the coordinates/components of the component in + * the indicated CoordinateSystem). + */ +EigenTransform CoordinateSystem::GetTransformation(CoordinateSystem const& pFrom, + CoordinateSystem const& pTo) { + CoordinateSystem const* a{&pFrom}; + CoordinateSystem const* b{&pTo}; CoordinateSystem const* commonBase{nullptr}; while (a != b && b != nullptr) { - a = &c1; + a = &pFrom; while (a != b && a != nullptr) { a = a->GetReference(); } @@ -26,18 +33,17 @@ EigenTransform CoordinateSystem::GetTransformation(CoordinateSystem const& c1, } EigenTransform t = EigenTransform::Identity(); - - auto* p = &c1; + auto* p = &pFrom; while (p != commonBase) { t = p->GetTransform() * t; p = p->GetReference(); } - p = &c2; + p = &pTo; while (p != commonBase) { - t = p->GetTransform().inverse(Eigen::TransformTraits::Isometry) * t; + t = t * p->GetTransform().inverse(Eigen::TransformTraits::Isometry); p = p->GetReference(); } diff --git a/Framework/Geometry/testGeometry.cc b/Framework/Geometry/testGeometry.cc index 3c7f63af445c847541fd2c3fc665aa8ae4d3198d..182f9c07d13e8351a8341be3490f1c64fca81707 100644 --- a/Framework/Geometry/testGeometry.cc +++ b/Framework/Geometry/testGeometry.cc @@ -95,6 +95,9 @@ TEST_CASE("transformations between CoordinateSystems") { QuantityVector<length_d> const zAxis{0_m, 0_m, 1_km}; QuantityVector<length_d> const yAxis{0_m, 7_nm, 0_m}; QuantityVector<length_d> const xAxis{2_m, 0_nm, 0_m}; + + QuantityVector<magnetic_flux_density_d> components{1. * tesla, 2. * tesla, 3. * tesla}; + Vector<magnetic_flux_density_d> v1(rootCS, components); double const angle = 90. / 180. * M_PI; @@ -104,7 +107,7 @@ TEST_CASE("transformations between CoordinateSystems") { CoordinateSystem combined = rootCS.rotate(xAxis, -angle); - auto comp1 = v1.GetComponents(rootCS); + auto comp1 = v1.GetComponents(rotated3); auto comp3 = v1.GetComponents(combined); REQUIRE((comp1 - comp3).norm().magnitude() == Approx(0).margin(absMargin)); }