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 50 of file ProjectPointOnMesh.cpp.

52{
53 // mathematical description of the plane spanned by the 2d element
54 // compute coefficients of the plane equation (Hesse normal form)
55 // d = scalar_product(normal, element_node[0])
56 auto const n = MeshLib::FaceRule::getSurfaceNormal(element).normalized();
57 auto const d = n.dot(element.getNode(0)->asEigenVector3d());
58 // insert node[0] and node[1] into plane equation and transpose the equation
59 // to node[2]
60 return (d - (node[0] * n[0] + node[1] * n[1])) / n[2];
61}
static Eigen::Vector3d getSurfaceNormal(Element const &e)
Returns the surface normal of a 2D element.
Definition FaceRule.cpp:33

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 14 of file ProjectPointOnMesh.cpp.

17{
18 auto is_right_of = [&node](MeshLib::Node const& a, MeshLib::Node const& b)
19 { return GeoLib::getOrientation(node, a, b) == GeoLib::Orientation::CW; };
20
21 for (auto const* e : elements)
22 {
23 auto const* nodes = e->getNodes();
24 if (e->getGeomType() == MeshLib::MeshElemType::TRIANGLE)
25 {
26 auto const& a = *nodes[0];
27 auto const& b = *nodes[1];
28 auto const& c = *nodes[2];
29 if (!is_right_of(a, b) && !is_right_of(b, c) && !is_right_of(c, a))
30 {
31 return e;
32 }
33 }
34 else if (e->getGeomType() == MeshLib::MeshElemType::QUAD)
35 {
36 auto const& a = *nodes[0];
37 auto const& b = *nodes[1];
38 auto const& c = *nodes[2];
39 auto const& d = *nodes[3];
40 if (!is_right_of(a, b) && !is_right_of(b, c) &&
41 !is_right_of(c, d) && !is_right_of(d, a))
42 {
43 return e;
44 }
45 }
46 }
47 return nullptr;
48}
Orientation getOrientation(MathLib::Point3d const &p0, MathLib::Point3d const &p1, MathLib::Point3d const &p2)

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

Referenced by getProjectedElement(), and main().