From e4c039cf5e2c1257ff1f6c8ae5938bf89d1fbcae Mon Sep 17 00:00:00 2001 From: Maximilian Reininghaus <maximilian.reininghaus@kit.edu> Date: Wed, 3 Oct 2018 15:24:41 +0200 Subject: [PATCH] fixed bug in geometry --- Framework/Geometry/CoordinateSystem.cc | 24 +++++++++++++++--------- Framework/Geometry/testGeometry.cc | 5 ++++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Framework/Geometry/CoordinateSystem.cc b/Framework/Geometry/CoordinateSystem.cc index db0dea29..b74808cd 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 3c7f63af..182f9c07 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)); } -- GitLab