preCICE v3.1.2
Loading...
Searching...
No Matches
geometry.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4#include <array>
6#include "utils/assertion.hpp"
7
8namespace precice {
9namespace math {
10
12namespace geometry {
13
21
34 const Eigen::Ref<const Eigen::Vector2d> &a,
35 const Eigen::Ref<const Eigen::Vector2d> &b,
36 const Eigen::Ref<const Eigen::Vector2d> &c,
37 const Eigen::Ref<const Eigen::Vector2d> &d,
38 Eigen::Ref<Eigen::Vector2d> & intersectionPoint);
39
53 const Eigen::Vector3d &pointOnPlane,
54 const Eigen::Vector3d &planeNormal,
55 const Eigen::Vector3d &firstPointSegment,
56 const Eigen::Vector3d &secondPointSegment,
57 Eigen::Vector3d & intersectionPoint);
58
70template <typename VECTORA_T, typename VECTORB_T, typename VECTORC_T>
71bool between(
72 const VECTORA_T &a,
73 const VECTORB_T &b,
74 const VECTORC_T &toCheck);
75
87template <typename Derived>
88bool collinear(
89 const Eigen::MatrixBase<Derived> &a,
90 const Eigen::MatrixBase<Derived> &b,
91 const Eigen::MatrixBase<Derived> &c);
92
104template <typename Derived>
105static bool parallel(
106 const Eigen::MatrixBase<Derived> &a,
107 const Eigen::MatrixBase<Derived> &b,
108 const Eigen::MatrixBase<Derived> &c,
109 const Eigen::MatrixBase<Derived> &d);
110
117double triangleArea(
118 const Eigen::VectorXd &a,
119 const Eigen::VectorXd &b,
120 const Eigen::VectorXd &c);
121
123double tetraVolume(
124 const Eigen::Vector3d &a,
125 const Eigen::Vector3d &b,
126 const Eigen::Vector3d &c,
127 const Eigen::Vector3d &d);
128
130Eigen::Vector2d projectVector(
131 const Eigen::Vector3d &vector,
132 const int indexDimensionToRemove);
133
142template <class Derived>
144 const Eigen::MatrixBase<Derived> &sidelengths,
145 const Eigen::MatrixBase<Derived> &center,
146 const Eigen::MatrixBase<Derived> &testPoint);
147
148// --------------------------------------------------------- HEADER DEFINITIONS
149
150template <typename VECTORA_T, typename VECTORB_T, typename VECTORC_T>
152 const VECTORA_T &a,
153 const VECTORB_T &b,
154 const VECTORC_T &toCheck)
155{
156 if (not collinear(a, b, toCheck)) {
157 return false;
158 }
159
160 if (a(0) != b(0)) {
161 return (math::greaterEquals(toCheck(0), a(0)) && math::greaterEquals(b(0), toCheck(0))) ||
162 (math::greaterEquals(a(0), toCheck(0)) && math::greaterEquals(toCheck(0), b(0)));
163 } else {
164 return (math::greaterEquals(toCheck(1), a(1)) && math::greaterEquals(b(1), toCheck(1))) ||
165 (math::greaterEquals(a(1), toCheck(1)) && math::greaterEquals(toCheck(1), b(1)));
166 }
167}
168
169template <typename Derived>
171 const Eigen::MatrixBase<Derived> &a,
172 const Eigen::MatrixBase<Derived> &b,
173 const Eigen::MatrixBase<Derived> &c)
174{
175 PRECICE_ASSERT(a.size() == b.size(), a.size(), b.size());
176 PRECICE_ASSERT(a.size() == c.size(), a.size(), c.size());
177 double triangleOutline = (b - a).norm() + (c - b).norm() + (a - c).norm();
178 if (math::equals(triangleArea(a, b, c) / triangleOutline, 0.0)) {
179 return true;
180 }
181 return false;
182}
183
184template <class Derived>
186 const Eigen::MatrixBase<Derived> &a,
187 const Eigen::MatrixBase<Derived> &b,
188 const Eigen::MatrixBase<Derived> &c,
189 const Eigen::MatrixBase<Derived> &d)
190{
191 if (math::equals(triangleArea(a, b, c), 0.0) and math::equals(triangleArea(a, b, d), 0.0))
192 return true;
193
194 return false;
195}
196
197template <class Derived>
199 const Eigen::MatrixBase<Derived> &sidelengths,
200 const Eigen::MatrixBase<Derived> &center,
201 const Eigen::MatrixBase<Derived> &testPoint)
202{
203 int dim = sidelengths.size();
204 Eigen::VectorXd toCenter = testPoint - center;
205 toCenter = toCenter.cwiseAbs();
206
207 double diff = 0.0;
208 bool touching = false;
209 for (int i = 0; i < dim; i++) {
210 diff = 0.5 * sidelengths(i) - toCenter(i);
211 if (math::greater(0.0, diff)) {
212 return NOT_CONTAINED;
213 }
214 if (math::equals(diff, 0.0)) {
215 touching = true;
216 }
217 }
218 if (touching) {
219 return TOUCHING;
220 }
221 return CONTAINED;
222}
223
228
230
231} // namespace geometry
232} // namespace math
233} // namespace precice
#define PRECICE_ASSERT(...)
Definition assertion.hpp:87
bool between(const VECTORA_T &a, const VECTORB_T &b, const VECTORC_T &toCheck)
Determines, if a point lies on the line segment defined by a, b.
Definition geometry.hpp:151
double triangleArea(const Eigen::VectorXd &a, const Eigen::VectorXd &b, const Eigen::VectorXd &c)
Computes the signed area of a triangle in 2D.
Definition geometry.cpp:93
double tetraVolume(const Eigen::Vector3d &a, const Eigen::Vector3d &b, const Eigen::Vector3d &c, const Eigen::Vector3d &d)
Computes the (unsigned) area of a triangle in 3D.
Definition geometry.cpp:116
Eigen::Vector2d projectVector(const Eigen::Vector3d &vector, int indexDimensionToRemove)
Projects a 3D vector to a 2D one by removing one dimension.
Definition geometry.cpp:125
int containedInHyperrectangle(const Eigen::MatrixBase< Derived > &sidelengths, const Eigen::MatrixBase< Derived > &center, const Eigen::MatrixBase< Derived > &testPoint)
Tests, if a vertex is contained in a hyperrectangle.
Definition geometry.hpp:198
bool lineIntersection(const Eigen::Ref< const Eigen::Vector2d > &a, const Eigen::Ref< const Eigen::Vector2d > &b, const Eigen::Ref< const Eigen::Vector2d > &c, const Eigen::Ref< const Eigen::Vector2d > &d, Eigen::Ref< Eigen::Vector2d > &intersectionPoint)
Determines the intersection point of two lines, if one exists.
Definition geometry.cpp:16
static bool parallel(const Eigen::MatrixBase< Derived > &a, const Eigen::MatrixBase< Derived > &b, const Eigen::MatrixBase< Derived > &c, const Eigen::MatrixBase< Derived > &d)
Determines, if two lines are parallel to each other.
Definition geometry.hpp:185
ResultConstants segmentPlaneIntersection(const Eigen::Vector3d &pointOnPlane, const Eigen::Vector3d &planeNormal, const Eigen::Vector3d &firstPointSegment, const Eigen::Vector3d &secondPointSegment, Eigen::Vector3d &intersectionPoint)
Determines the intersection point of a segment with a plane in 3D.
Definition geometry.cpp:42
bool collinear(const Eigen::MatrixBase< Derived > &a, const Eigen::MatrixBase< Derived > &b, const Eigen::MatrixBase< Derived > &c)
Determines, if three points are collinear (on one line)
Definition geometry.hpp:170
ConvexityResult isConvexQuad(std::array< Eigen::VectorXd, 4 > coords)
Definition geometry.cpp:143
constexpr bool equals(const Eigen::MatrixBase< DerivedA > &A, const Eigen::MatrixBase< DerivedB > &B, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares two Eigen::MatrixBase for equality up to tolerance.
std::enable_if< std::is_arithmetic< Scalar >::value, bool >::type greaterEquals(Scalar A, Scalar B, Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
std::enable_if< std::is_arithmetic< Scalar >::value, bool >::type greater(Scalar A, Scalar B, Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
Main namespace of the precice library.