From 853ddceef52344b3f28a395370448fb9be2f4064 Mon Sep 17 00:00:00 2001 From: Maximilian Reininghaus <maximilian.reininghaus@kit.edu> Date: Thu, 2 Aug 2018 15:52:38 +0200 Subject: [PATCH] more functionality for geometry --- Framework/Geometry/QuantityVector.h | 10 ++++++++-- Framework/Geometry/Sphere.h | 27 +++++++++++++++++++++++++++ Framework/Geometry/Vector.h | 22 ++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 Framework/Geometry/Sphere.h diff --git a/Framework/Geometry/QuantityVector.h b/Framework/Geometry/QuantityVector.h index c874f2277..a4cab185d 100644 --- a/Framework/Geometry/QuantityVector.h +++ b/Framework/Geometry/QuantityVector.h @@ -11,6 +11,7 @@ class QuantityVector { protected: using Quantity = phys::units::quantity<dim, double>; + using QuantitySquared = decltype(Quantity(phys::units::detail::magnitude_tag, 0) * Quantity(phys::units::detail::magnitude_tag, 0)); public: Eigen::Vector3d eVector; @@ -25,16 +26,21 @@ public: { } - Quantity operator[](size_t index) const + auto operator[](size_t index) const { return Quantity(phys::units::detail::magnitude_tag, eVector[index]); } - Quantity norm() const + auto norm() const { return Quantity(phys::units::detail::magnitude_tag, eVector.norm()); } + auto squaredNorm() const + { + return QuantitySquared(phys::units::detail::magnitude_tag, eVector.squaredNorm()); + } + auto operator+(QuantityVector<dim> const& pQVec) const { return QuantityVector<dim>(eVector + pQVec.eVector); diff --git a/Framework/Geometry/Sphere.h b/Framework/Geometry/Sphere.h new file mode 100644 index 000000000..2a3ecf1af --- /dev/null +++ b/Framework/Geometry/Sphere.h @@ -0,0 +1,27 @@ +#ifndef SPHERE_H_ +#define SPHERE_H_ + +#include "Point.h" +#include <phys/units/quantity.hpp> + +class Sphere +{ + using Length = phys::units::quantity<phys::units::length_d, double>; + Point center; + Length const radius; + +public: + Sphere(Point const& pCenter, Length const pRadius) : + center(pCenter), radius(pRadius) + { + + } + + auto isInside(Point const& p) const + { + return radius*radius > (center - p).squaredNorm(); + } + +}; + +#endif diff --git a/Framework/Geometry/Vector.h b/Framework/Geometry/Vector.h index 6e8b7fbbc..d6fff9842 100644 --- a/Framework/Geometry/Vector.h +++ b/Framework/Geometry/Vector.h @@ -49,6 +49,28 @@ public: return BaseVector<dim>::qVector.norm(); } + auto squaredNorm() const + { + return BaseVector<dim>::qVector.squaredNorm(); + } + + template <typename dim2> + auto parallelProjectionOnto(BaseVector<dim2> const& pVec, CoordinateSystem const& pCS) const + { + auto const ourCompVec = getComponents(pCS); + auto const otherCompVec = pVec.getComponents(pVec); + auto const& a = ourCompVec.eVector; + auto const& b = otherCompVec.eVector; + + return Vector<dim>(pCS, (a * b) / b.squaredNorm() * b); + } + + template <typename dim2> + auto parallelProjectionOnto(BaseVector<dim2> const& pVec) + { + return parallelProjectionOnto<dim2>(pVec, *BaseVector<dim>::cs); + } + //~ template <typename dim2> //~ auto operator*(Vector<dim2> const& pVec) //~ { -- GitLab