IAP GITLAB

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

first implementation of geometry

parent 5f19498a
No related branches found
No related tags found
No related merge requests found
#ifndef BASEVECTOR_H_
#define BASEVECTOR_H_
#include "QuantityVector.h"
#include "CoordinateSystem.h"
template <typename dim>
class BaseVector
{
protected:
QuantityVector<dim> qVector;
CoordinateSystem const* cs;
public:
BaseVector(CoordinateSystem const& pCS, QuantityVector<dim> pQVector) :
qVector(pQVector), cs(&pCS)
{
}
};
#endif
#include "CoordinateSystem.h"
EigenTransform CoordinateSystem::getTransformation(CoordinateSystem const& c1, CoordinateSystem const& c2)
{
CoordinateSystem const* a{&c1};
CoordinateSystem const* b{&c2};
CoordinateSystem const* commonBase{nullptr};
while (a != b && b != nullptr)
{
a = &c1;
while (a != b && a != nullptr)
{
a = a->getReference();
}
if (a == b)
break;
b = b->getReference();
}
if (a == b && a != nullptr)
{
commonBase = a;
}
else
{
throw std::string("no connection between coordinate systems found!");
}
EigenTransform t = EigenTransform::Identity();
auto* p = &c1;
while (p != commonBase)
{
t = p->getTransform() * t;
p = p->getReference();
}
p = &c2;
while (p != commonBase)
{
t = p->getTransform().inverse(Eigen::TransformTraits::Isometry) * t;
p = p->getReference();
}
return t;
}
#ifndef COORDINATESYSTEM_H_
#define COORDINATESYSTEM_H_
#include "QuantityVector.h"
#include <Eigen/Dense>
#include <phys/units/quantity.hpp>
typedef Eigen::Transform<double, 3, Eigen::Affine> EigenTransform;
typedef Eigen::Translation<double, 3> EigenTranslation;
class CoordinateSystem
{
CoordinateSystem const* reference = nullptr;
EigenTransform transf;
CoordinateSystem(CoordinateSystem const& reference, EigenTransform const& transf) :
reference(&reference),
transf(transf)
{
}
public:
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;
return *this;
}
auto translate(QuantityVector<phys::units::length_d> vector) const
{
EigenTransform const translation{EigenTranslation(vector.eVector)};
return CoordinateSystem(*this, translation);
}
auto rotate(QuantityVector<phys::units::length_d> axis, double angle) const
{
EigenTransform const rotation{Eigen::AngleAxisd(M_PI / 6, axis.eVector.normalized())};
return CoordinateSystem(*this, rotation);
}
auto translateAndRotate(QuantityVector<phys::units::length_d> translation, QuantityVector<phys::units::length_d> axis, double angle)
{
EigenTransform const transf{Eigen::AngleAxisd(M_PI / 6, axis.eVector.normalized()) * EigenTranslation(translation.eVector)};
return CoordinateSystem(*this, transf);
}
auto const* getReference() const
{
return reference;
}
auto const& getTransform() const
{
return transf;
}
};
#endif
#ifndef POINT_H_
#define POINT_H_
#include "BaseVector.h"
#include "QuantityVector.h"
#include <phys/units/quantity.hpp>
class Point : public BaseVector<phys::units::length_d>
{
using Length = phys::units::quantity<phys::units::length_d, double>;
public:
Point(CoordinateSystem const& pCS, QuantityVector<phys::units::length_d> pQVector) :
BaseVector<phys::units::length_d>(pCS, pQVector)
{
}
Point(CoordinateSystem const& cs, Length x, Length y, Length z) :
BaseVector<phys::units::length_d>(cs, {x, y, z})
{
}
auto getCoordinates() const
{
return BaseVector<phys::units::length_d>::qVector;
}
auto getCoordinates(CoordinateSystem const& pCS) const
{
if (&pCS == BaseVector<phys::units::length_d>::cs)
{
return BaseVector<phys::units::length_d>::qVector;
}
else
{
return QuantityVector<phys::units::length_d>(CoordinateSystem::getTransformation(*BaseVector<phys::units::length_d>::cs, pCS) * BaseVector<phys::units::length_d>::qVector.eVector);
}
}
void rebase(CoordinateSystem const& pCS)
{
BaseVector<phys::units::length_d>::qVector = getCoordinates(pCS);
BaseVector<phys::units::length_d>::cs = &pCS;
}
};
#endif
#ifndef QUANTITYVECTOR_H_
#define QUANTITYVECTOR_H_
#include <phys/units/quantity.hpp>
#include <phys/units/io.hpp>
#include <Eigen/Dense>
#include <iostream>
template <typename dim>
class QuantityVector
{
protected:
using Quantity = phys::units::quantity<dim, double>;
public:
Eigen::Vector3d eVector;
QuantityVector(Quantity a, Quantity b, Quantity c) :
eVector{a.magnitude(), b.magnitude(), c.magnitude()}
{
}
QuantityVector(Eigen::Vector3d pBareVector) :
eVector(pBareVector)
{
}
Quantity operator[](size_t index) const
{
return Quantity(phys::units::detail::magnitude_tag, eVector[index]);
}
};
template <typename dim>
auto& operator<<(std::ostream& os, QuantityVector<dim> qv)
{
os << '(' << qv.eVector(0) << ' ' << qv.eVector(1) << ' ' << qv.eVector(2)
<< ") " << phys::units::to_unit_symbol(phys::units::quantity<dim, double>());
return os;
}
#endif
#ifndef VECTOR_H_
#define VECTOR_H_
#include "BaseVector.h"
#include "QuantityVector.h"
#include <phys/units/quantity.hpp>
template <typename dim>
class Vector : public BaseVector<dim>
{
using Quantity = phys::units::quantity<dim, double>;
Vector(CoordinateSystem const& pCS, QuantityVector<dim> pQVector) :
BaseVector<Quantity>(pCS, pQVector)
{
}
public:
Vector(CoordinateSystem const& cs, Quantity x, Quantity y, Quantity z) :
BaseVector<dim>(cs, QuantityVector<dim>(x, y, z))
{
}
auto getComponents() const
{
return BaseVector<dim>::qVector;
}
auto getComponents(CoordinateSystem const& pCS) const
{
if (&pCS == BaseVector<dim>::cs)
{
return BaseVector<dim>::qVector;
}
else
{
return QuantityVector<dim>(CoordinateSystem::getTransformation(*BaseVector<dim>::cs, pCS).linear() * BaseVector<dim>::qVector.eVector);
}
}
void rebase(CoordinateSystem const& pCS)
{
BaseVector<dim>::qVector = getComponents(pCS);
BaseVector<dim>::cs = &pCS;
}
auto norm() const
{
return Quantity(BaseVector<dim>::qVector.eVector.norm());
}
//~ template <typename dim2>
//~ auto operator*(Vector<dim2> const& pVec)
//~ {
//~ auto constexpr resulting_dim = dimension
//~ return Vector<
//~ }
};
#endif
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