OGS
MeshToolsLib::ProjectPointOnMesh Namespace Reference

Functions

MeshLib::Element const * getProjectedElement (std::vector< const MeshLib::Element * > const &elements, MathLib::Point3d const &node)
 
double getElevation (MeshLib::Element const &element, MathLib::Point3d const &node)
 

Function Documentation

◆ getElevation()

double MeshToolsLib::ProjectPointOnMesh::getElevation ( MeshLib::Element const & element,
MathLib::Point3d const & node )

Returns the z-coordinate of a point projected onto the plane defined by a mesh element.

Definition at line 57 of file ProjectPointOnMesh.cpp.

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}
static Eigen::Vector3d getSurfaceNormal(Element const &e)
Returns the surface normal of a 2D element.
Definition FaceRule.cpp:40

References MathLib::Point3d::asEigenVector3d(), MeshLib::Element::getNode(), and MeshLib::FaceRule::getSurfaceNormal().

Referenced by main(), and voteMatId().

◆ getProjectedElement()

MeshLib::Element const * MeshToolsLib::ProjectPointOnMesh::getProjectedElement ( std::vector< const MeshLib::Element * > const & elements,
MathLib::Point3d const & node )

Returns the element in which the given node is located when projected onto a mesh, or nullptr if no such element was found.

Definition at line 21 of file ProjectPointOnMesh.cpp.

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}
Orientation getOrientation(MathLib::Point3d const &p0, MathLib::Point3d const &p1, MathLib::Point3d const &p2)

References GeoLib::CW, MeshLib::Element::getNodes(), GeoLib::getOrientation(), MeshLib::QUAD, and MeshLib::TRIANGLE.

Referenced by getProjectedElement(), and main().