IAP GITLAB

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

fixed bug in geometry

parent 7cfacb9c
No related branches found
No related tags found
No related merge requests found
...@@ -2,14 +2,21 @@ ...@@ -2,14 +2,21 @@
using namespace corsika::geometry; using namespace corsika::geometry;
EigenTransform CoordinateSystem::GetTransformation(CoordinateSystem const& c1, /**
CoordinateSystem const& c2) { * returns the transformation matrix necessary to transform primitives with coordinates
CoordinateSystem const* a{&c1}; * in \a pFrom to \a pTo, e.g.
CoordinateSystem const* b{&c2}; * \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}; CoordinateSystem const* commonBase{nullptr};
while (a != b && b != nullptr) { while (a != b && b != nullptr) {
a = &c1; a = &pFrom;
while (a != b && a != nullptr) { a = a->GetReference(); } while (a != b && a != nullptr) { a = a->GetReference(); }
...@@ -26,18 +33,17 @@ EigenTransform CoordinateSystem::GetTransformation(CoordinateSystem const& c1, ...@@ -26,18 +33,17 @@ EigenTransform CoordinateSystem::GetTransformation(CoordinateSystem const& c1,
} }
EigenTransform t = EigenTransform::Identity(); EigenTransform t = EigenTransform::Identity();
auto* p = &pFrom;
auto* p = &c1;
while (p != commonBase) { while (p != commonBase) {
t = p->GetTransform() * t; t = p->GetTransform() * t;
p = p->GetReference(); p = p->GetReference();
} }
p = &c2; p = &pTo;
while (p != commonBase) { while (p != commonBase) {
t = p->GetTransform().inverse(Eigen::TransformTraits::Isometry) * t; t = t * p->GetTransform().inverse(Eigen::TransformTraits::Isometry);
p = p->GetReference(); p = p->GetReference();
} }
......
...@@ -95,6 +95,9 @@ TEST_CASE("transformations between CoordinateSystems") { ...@@ -95,6 +95,9 @@ TEST_CASE("transformations between CoordinateSystems") {
QuantityVector<length_d> const zAxis{0_m, 0_m, 1_km}; 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 yAxis{0_m, 7_nm, 0_m};
QuantityVector<length_d> const xAxis{2_m, 0_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; double const angle = 90. / 180. * M_PI;
...@@ -104,7 +107,7 @@ TEST_CASE("transformations between CoordinateSystems") { ...@@ -104,7 +107,7 @@ TEST_CASE("transformations between CoordinateSystems") {
CoordinateSystem combined = rootCS.rotate(xAxis, -angle); CoordinateSystem combined = rootCS.rotate(xAxis, -angle);
auto comp1 = v1.GetComponents(rootCS); auto comp1 = v1.GetComponents(rotated3);
auto comp3 = v1.GetComponents(combined); auto comp3 = v1.GetComponents(combined);
REQUIRE((comp1 - comp3).norm().magnitude() == Approx(0).margin(absMargin)); REQUIRE((comp1 - comp3).norm().magnitude() == Approx(0).margin(absMargin));
} }
......
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