IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 532fcfec authored by Maximilian Reininghaus's avatar Maximilian Reininghaus :vulcan: Committed by Ralf Ulrich
Browse files

test and fix of CoordinateSystem::RotateToZ()

parent e2946495
No related branches found
No related tags found
1 merge request!194Resolve "Pythia 8 crash during decay of particles::DsMinus and particles::DsPlus"
...@@ -72,19 +72,19 @@ namespace corsika::geometry { ...@@ -72,19 +72,19 @@ namespace corsika::geometry {
Eigen::Matrix3d A, B; Eigen::Matrix3d A, B;
if (s > 0) { if (s > 0) {
A << 1, 0, -a1, // comment to prevent clang-format A << 1, 0, a1, // comment to prevent clang-format
0, 1, -a2, // . 0, 1, a2, // .
a1, a2, 1; // . -a1, -a2, 1; // .
B << -a1 * a1 * c, -a1 * a2 * c, 0, // . B << -a1 * a1 * c, -a1 * a2 * c, 0, // .
-a1 * a2 * c, -a2 * a2 * c, 0, // . -a1 * a2 * c, -a2 * a2 * c, 0, // .
0, 0, -(a1 * a1 + a2 * a2) * c; // . 0, 0, -(a1 * a1 + a2 * a2) * c; // .
} else { } else {
A << 1, 0, a1, // . A << 1, 0, a1, // .
0, -1, -a2, // . 0, -1, a2, // .
a1, a2, -1; // . a1, -a2, -1; // .
B << -a1 * a1 * c, -a1 * a2 * c, 0, // . B << -a1 * a1 * c, +a1 * a2 * c, 0, // .
+a1 * a2 * c, +a2 * a2 * c, 0, // . -a1 * a2 * c, +a2 * a2 * c, 0, // .
0, 0, (a1 * a1 + a2 * a2) * c; // . 0, 0, (a1 * a1 + a2 * a2) * c; // .
} }
......
...@@ -123,6 +123,63 @@ TEST_CASE("transformations between CoordinateSystems") { ...@@ -123,6 +123,63 @@ TEST_CASE("transformations between CoordinateSystems") {
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));
} }
SECTION("RotateToZ positive") {
Vector const v{rootCS, 0_m, 1_m, 1_m};
auto const csPrime = rootCS.RotateToZ(v);
auto const transform = csPrime.GetTransform().matrix();
Vector const zPrime{csPrime, 0_m, 0_m, 5_m};
Vector const xPrime{csPrime, 5_m, 0_m, 0_m};
Vector const yPrime{csPrime, 0_m, 5_m, 0_m};
CHECK(zPrime.dot(v).magnitude() > 0);
CHECK(zPrime.GetComponents(rootCS)[1].magnitude() ==
Approx(zPrime.GetComponents(rootCS)[2].magnitude()));
CHECK(zPrime.GetComponents(rootCS)[0].magnitude() == Approx(0));
CHECK(xPrime.GetComponents(rootCS).eVector.dot(
yPrime.GetComponents(rootCS).eVector) == Approx(0));
CHECK(zPrime.GetComponents(rootCS).eVector.dot(
xPrime.GetComponents(rootCS).eVector) == Approx(0));
CHECK(yPrime.GetComponents(rootCS).eVector.dot(
zPrime.GetComponents(rootCS).eVector) == Approx(0));
CHECK(yPrime.GetComponents(rootCS).eVector.dot(
yPrime.GetComponents(rootCS).eVector) == Approx((5_m * 5_m).magnitude()));
CHECK(xPrime.GetComponents(rootCS).eVector.dot(
xPrime.GetComponents(rootCS).eVector) == Approx((5_m * 5_m).magnitude()));
CHECK(zPrime.GetComponents(rootCS).eVector.dot(
zPrime.GetComponents(rootCS).eVector) == Approx((5_m * 5_m).magnitude()));
}
SECTION("RotateToZ negative") {
Vector const v{rootCS, 0_m, 0_m, -1_m};
auto const csPrime = rootCS.RotateToZ(v);
auto const transform = csPrime.GetTransform().matrix();
Vector const zPrime{csPrime, 0_m, 0_m, 5_m};
Vector const xPrime{csPrime, 5_m, 0_m, 0_m};
Vector const yPrime{csPrime, 0_m, 5_m, 0_m};
CHECK(zPrime.dot(v).magnitude() > 0);
CHECK(xPrime.GetComponents(rootCS).eVector.dot(v.GetComponents().eVector) ==
Approx(0));
CHECK(yPrime.GetComponents(rootCS).eVector.dot(v.GetComponents().eVector) ==
Approx(0));
CHECK(xPrime.GetComponents(rootCS).eVector.dot(
yPrime.GetComponents(rootCS).eVector) == Approx(0));
CHECK(zPrime.GetComponents(rootCS).eVector.dot(
xPrime.GetComponents(rootCS).eVector) == Approx(0));
CHECK(yPrime.GetComponents(rootCS).eVector.dot(
zPrime.GetComponents(rootCS).eVector) == Approx(0));
CHECK(yPrime.GetComponents(rootCS).eVector.dot(
yPrime.GetComponents(rootCS).eVector) == Approx((5_m * 5_m).magnitude()));
CHECK(xPrime.GetComponents(rootCS).eVector.dot(
xPrime.GetComponents(rootCS).eVector) == Approx((5_m * 5_m).magnitude()));
CHECK(zPrime.GetComponents(rootCS).eVector.dot(
zPrime.GetComponents(rootCS).eVector) == Approx((5_m * 5_m).magnitude()));
}
} }
TEST_CASE("Sphere") { TEST_CASE("Sphere") {
......
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