OGS
ProjectPointOnMesh.cpp
Go to the documentation of this file.
1
12#include "MathLib/Point3d.h"
16
17namespace MeshToolsLib
18{
19namespace ProjectPointOnMesh
20{
22 std::vector<const MeshLib::Element*> const& elements,
23 MathLib::Point3d const& node)
24{
25 auto is_right_of = [&node](MeshLib::Node const& a, MeshLib::Node const& b)
26 { return GeoLib::getOrientation(node, a, b) == GeoLib::Orientation::CW; };
27
28 for (auto const* e : elements)
29 {
30 auto const* nodes = e->getNodes();
31 if (e->getGeomType() == MeshLib::MeshElemType::TRIANGLE)
32 {
33 auto const& a = *nodes[0];
34 auto const& b = *nodes[1];
35 auto const& c = *nodes[2];
36 if (!is_right_of(a, b) && !is_right_of(b, c) && !is_right_of(c, a))
37 {
38 return e;
39 }
40 }
41 else if (e->getGeomType() == MeshLib::MeshElemType::QUAD)
42 {
43 auto const& a = *nodes[0];
44 auto const& b = *nodes[1];
45 auto const& c = *nodes[2];
46 auto const& d = *nodes[3];
47 if (!is_right_of(a, b) && !is_right_of(b, c) &&
48 !is_right_of(c, d) && !is_right_of(d, a))
49 {
50 return e;
51 }
52 }
53 }
54 return nullptr;
55}
56
57double getElevation(MeshLib::Element const& element,
58 MathLib::Point3d const& node)
59{
60 // mathematical description of the plane spanned by the 2d element
61 // compute coefficients of the plane equation (Hesse normal form)
62 // d = scalar_product(normal, element_node[0])
63 auto const n = MeshLib::FaceRule::getSurfaceNormal(element).normalized();
64 auto const d = n.dot(element.getNode(0)->asEigenVector3d());
65 // insert node[0] and node[1] into plane equation and transpose the equation
66 // to node[2]
67 return (d - (node[0] * n[0] + node[1] * n[1])) / n[2];
68}
69
70} // namespace ProjectPointOnMesh
71
72} // namespace MeshToolsLib
Definition of analytical geometry functions.
Definition of the Point3d class.
Definition of the Quad class.
Definition of the Tri class.
Eigen::Vector3d const & asEigenVector3d() const
Definition Point3d.h:63
virtual const Node * getNode(unsigned idx) const =0
virtual Node *const * getNodes() const =0
Get array of element nodes.
static Eigen::Vector3d getSurfaceNormal(Element const &e)
Returns the surface normal of a 2D element.
Definition FaceRule.cpp:40
Orientation getOrientation(MathLib::Point3d const &p0, MathLib::Point3d const &p1, MathLib::Point3d const &p2)
double getElevation(MeshLib::Element const &element, MathLib::Point3d const &node)
MeshLib::Element const * getProjectedElement(std::vector< const MeshLib::Element * > const &elements, MathLib::Point3d const &node)