IAP GITLAB

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

addition & subtraction for Vector & Point

parent 4657b4de
No related branches found
No related tags found
No related merge requests found
...@@ -3,13 +3,13 @@ ...@@ -3,13 +3,13 @@
#include "BaseVector.h" #include "BaseVector.h"
#include "QuantityVector.h" #include "QuantityVector.h"
#include "Vector.h"
#include <phys/units/quantity.hpp> #include <phys/units/quantity.hpp>
class Point : public BaseVector<phys::units::length_d> class Point : public BaseVector<phys::units::length_d>
{ {
using Length = phys::units::quantity<phys::units::length_d, double>; using Length = phys::units::quantity<phys::units::length_d, double>;
public: public:
Point(CoordinateSystem const& pCS, QuantityVector<phys::units::length_d> pQVector) : Point(CoordinateSystem const& pCS, QuantityVector<phys::units::length_d> pQVector) :
BaseVector<phys::units::length_d>(pCS, pQVector) BaseVector<phys::units::length_d>(pCS, pQVector)
...@@ -43,6 +43,17 @@ public: ...@@ -43,6 +43,17 @@ public:
BaseVector<phys::units::length_d>::qVector = getCoordinates(pCS); BaseVector<phys::units::length_d>::qVector = getCoordinates(pCS);
BaseVector<phys::units::length_d>::cs = &pCS; BaseVector<phys::units::length_d>::cs = &pCS;
} }
Point operator+(Vector<phys::units::length_d> const& pVec) const
{
return Point(*BaseVector<phys::units::length_d>::cs, getCoordinates() + pVec.getComponents(*BaseVector<phys::units::length_d>::cs));
}
Vector<phys::units::length_d> operator-(Point const& pB) const
{
auto& cs = *BaseVector<phys::units::length_d>::cs;
return Vector<phys::units::length_d>(cs, getCoordinates() - pB.getCoordinates(cs));
}
}; };
#endif #endif
...@@ -29,6 +29,23 @@ public: ...@@ -29,6 +29,23 @@ public:
{ {
return Quantity(phys::units::detail::magnitude_tag, eVector[index]); return Quantity(phys::units::detail::magnitude_tag, eVector[index]);
} }
Quantity norm() const
{
return Quantity(phys::units::detail::magnitude_tag, eVector.norm());
}
auto operator+(QuantityVector<dim> const& pQVec) const
{
return QuantityVector<dim>(eVector + pQVec.eVector);
}
auto operator-(QuantityVector<dim> const& pQVec) const
{
return QuantityVector<dim>(eVector - pQVec.eVector);
}
//auto operator*(
}; };
template <typename dim> template <typename dim>
......
...@@ -10,13 +10,12 @@ class Vector : public BaseVector<dim> ...@@ -10,13 +10,12 @@ class Vector : public BaseVector<dim>
{ {
using Quantity = phys::units::quantity<dim, double>; using Quantity = phys::units::quantity<dim, double>;
public:
Vector(CoordinateSystem const& pCS, QuantityVector<dim> pQVector) : Vector(CoordinateSystem const& pCS, QuantityVector<dim> pQVector) :
BaseVector<Quantity>(pCS, pQVector) BaseVector<dim>(pCS, pQVector)
{ {
} }
public:
Vector(CoordinateSystem const& cs, Quantity x, Quantity y, Quantity z) : Vector(CoordinateSystem const& cs, Quantity x, Quantity y, Quantity z) :
BaseVector<dim>(cs, QuantityVector<dim>(x, y, z)) BaseVector<dim>(cs, QuantityVector<dim>(x, y, z))
{ {
...@@ -47,7 +46,7 @@ public: ...@@ -47,7 +46,7 @@ public:
auto norm() const auto norm() const
{ {
return Quantity(BaseVector<dim>::qVector.eVector.norm()); return BaseVector<dim>::qVector.norm();
} }
//~ template <typename dim2> //~ template <typename dim2>
......
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