IAP GITLAB

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

factory method for creation of root CS

parent 0213fab4
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ using namespace corsika::units::si;
int main() {
// define the root coordinate system
CoordinateSystem root;
auto const root = CoordinateSystem::CreateRootCS();
// another CS defined by a translation relative to the root CS
CoordinateSystem cs2 = root.translate({0_m, 0_m, 1_m});
......@@ -50,10 +50,10 @@ int main() {
std::cout << "p2-p1 norm^2: " << norm << std::endl;
Sphere s(p1, 10_m); // define a sphere around a point with a radius
std::cout << "p1 inside s: " << s.isInside(p2) << std::endl;
std::cout << "p1 inside s: " << s.Contains(p2) << std::endl;
Sphere s2(p1, 3_um); // another sphere
std::cout << "p1 inside s2: " << s2.isInside(p2) << std::endl;
std::cout << "p1 inside s2: " << s2.Contains(p2) << std::endl;
// let's try parallel projections:
auto const v1 = Vector<length_d>(root, {1_m, 1_m, 0_m});
......
......@@ -22,8 +22,7 @@ using namespace corsika::geometry;
using namespace corsika::units::si;
int main() {
CoordinateSystem root;
auto const root = CoordinateSystem::CreateRootCS();
Point const r0(root, {0_m, 0_m, 0_m});
auto const omegaC = 2 * M_PI * 1_Hz;
......
......@@ -66,7 +66,7 @@ namespace corsika::cascade {
void Step(Particle& particle) {
[[maybe_unused]] double nextStep = fProcesseList.MinStepLength(particle);
// corsika::utls::ignore(nextStep);
corsika::geometry::CoordinateSystem root;
auto const root = corsika::geometry::CoordinateSystem::CreateRootCS();
corsika::geometry::LineTrajectory
trajectory( // trajectory is not yet used. this is a dummy.
corsika::geometry::Point(root, {0_m, 0_m, 0_m}),
......
......@@ -30,15 +30,17 @@ namespace corsika::geometry {
CoordinateSystem(CoordinateSystem const& reference, EigenTransform const& transf)
: reference(&reference)
, transf(transf) {}
CoordinateSystem()
: // for creating the root CS
transf(EigenTransform::Identity()) {}
public:
static auto CreateRootCS() { return CoordinateSystem(); }
static EigenTransform GetTransformation(CoordinateSystem const& c1,
CoordinateSystem const& c2);
CoordinateSystem()
: // for creating the root CS
transf(EigenTransform::Identity()) {}
auto& operator=(const CoordinateSystem& pCS) {
reference = pCS.reference;
transf = pCS.transf;
......@@ -52,6 +54,10 @@ namespace corsika::geometry {
}
auto rotate(QuantityVector<phys::units::length_d> axis, double angle) const {
if (axis.eVector.isZero()) {
throw std::string("null-vector given as axis parameter");
}
EigenTransform const rotation{Eigen::AngleAxisd(angle, axis.eVector.normalized())};
return CoordinateSystem(*this, rotation);
......@@ -59,6 +65,10 @@ namespace corsika::geometry {
auto translateAndRotate(QuantityVector<phys::units::length_d> translation,
QuantityVector<phys::units::length_d> axis, double angle) {
if (axis.eVector.isZero()) {
throw std::string("null-vector given as axis parameter");
}
EigenTransform const transf{Eigen::AngleAxisd(angle, axis.eVector.normalized()) *
EigenTranslation(translation.eVector)};
......
......@@ -26,8 +26,8 @@ namespace corsika::geometry {
: center(pCenter)
, radius(pRadius) {}
//! returns true if the Point p is within the sphere
auto isInside(Point const& p) const {
//! returns true if the Point \a p is within the sphere
auto Contains(Point const& p) const {
return radius * radius > (center - p).squaredNorm();
}
};
......
......@@ -28,7 +28,7 @@ using namespace corsika::units::si;
double constexpr absMargin = 1.0e-8;
TEST_CASE("transformations between CoordinateSystems") {
CoordinateSystem rootCS;
CoordinateSystem rootCS = CoordinateSystem::CreateRootCS();
REQUIRE(CoordinateSystem::GetTransformation(rootCS, rootCS)
.isApprox(EigenTransform::Identity()));
......@@ -45,7 +45,7 @@ TEST_CASE("transformations between CoordinateSystems") {
Approx(0).margin(absMargin));
SECTION("unconnected CoordinateSystems") {
CoordinateSystem rootCS2;
CoordinateSystem rootCS2 = CoordinateSystem::CreateRootCS();
REQUIRE_THROWS(CoordinateSystem::GetTransformation(rootCS, rootCS2));
}
......@@ -126,18 +126,18 @@ TEST_CASE("transformations between CoordinateSystems") {
}
TEST_CASE("Sphere") {
CoordinateSystem rootCS;
CoordinateSystem rootCS = CoordinateSystem::CreateRootCS();
Point center(rootCS, {0_m, 3_m, 4_m});
Sphere sphere(center, 5_m);
SECTION("isInside") {
REQUIRE_FALSE(sphere.isInside(Point(rootCS, {100_m, 0_m, 0_m})));
REQUIRE(sphere.isInside(Point(rootCS, {2_m, 3_m, 4_m})));
REQUIRE_FALSE(sphere.Contains(Point(rootCS, {100_m, 0_m, 0_m})));
REQUIRE(sphere.Contains(Point(rootCS, {2_m, 3_m, 4_m})));
}
}
TEST_CASE("Trajectories") {
CoordinateSystem rootCS;
CoordinateSystem rootCS = CoordinateSystem::CreateRootCS();
Point r0(rootCS, {0_m, 0_m, 0_m});
SECTION("Line") {
......
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