Skip to content
Snippets Groups Projects
Commit 6e60244e authored by Tom Fischer's avatar Tom Fischer
Browse files

[GL] New function rotatePolygonToXY().

parent 081a7cf9
No related branches found
No related tags found
No related merge requests found
...@@ -36,41 +36,13 @@ ...@@ -36,41 +36,13 @@
#include "MeshLib/Elements/Element.h" #include "MeshLib/Elements/Element.h"
#include "MeshLib/MeshEditing/ElementValueModification.h" #include "MeshLib/MeshEditing/ElementValueModification.h"
GeoLib::Polygon rotatePolygonToXY(GeoLib::Polygon const& polygon_in,
MathLib::Vector3 & plane_normal)
{
// 1 copy all points
std::vector<GeoLib::Point*> *polygon_pnts(new std::vector<GeoLib::Point*>);
for (std::size_t k(0); k < polygon_in.getNumberOfPoints(); k++)
polygon_pnts->push_back (new GeoLib::Point (*(polygon_in.getPoint(k))));
// 2 rotate points
double d_polygon (0.0);
GeoLib::getNewellPlane (*polygon_pnts, plane_normal, d_polygon);
MathLib::DenseMatrix<double> rot_mat(3,3);
GeoLib::computeRotationMatrixToXY(plane_normal, rot_mat);
GeoLib::rotatePoints(rot_mat, *polygon_pnts);
// 3 set z coord to zero
std::for_each(polygon_pnts->begin(), polygon_pnts->end(),
[] (GeoLib::Point* p) { (*p)[2] = 0.0; }
);
// 4 create new polygon
GeoLib::Polyline rot_polyline(*polygon_pnts);
for (std::size_t k(0); k < polygon_in.getNumberOfPoints(); k++)
rot_polyline.addPoint(k);
rot_polyline.addPoint(0);
return GeoLib::Polygon(rot_polyline);
}
std::vector<bool> markNodesOutSideOfPolygon( std::vector<bool> markNodesOutSideOfPolygon(
std::vector<MeshLib::Node*> const& nodes, std::vector<MeshLib::Node*> const& nodes,
GeoLib::Polygon const& polygon) GeoLib::Polygon const& polygon)
{ {
// *** rotate polygon to xy_plane // *** rotate polygon to xy_plane
MathLib::Vector3 normal; MathLib::Vector3 normal;
GeoLib::Polygon rot_polygon(rotatePolygonToXY(polygon, normal)); GeoLib::Polygon rot_polygon(GeoLib::rotatePolygonToXY(polygon, normal));
// *** rotate mesh nodes to xy-plane // *** rotate mesh nodes to xy-plane
// 1 copy all mesh nodes to GeoLib::Points // 1 copy all mesh nodes to GeoLib::Points
......
...@@ -579,5 +579,32 @@ void computeAndInsertAllIntersectionPoints(GeoLib::PointVec &pnt_vec, ...@@ -579,5 +579,32 @@ void computeAndInsertAllIntersectionPoints(GeoLib::PointVec &pnt_vec,
} }
} }
GeoLib::Polygon rotatePolygonToXY(GeoLib::Polygon const& polygon_in,
MathLib::Vector3 & plane_normal)
{
// 1 copy all points
std::vector<GeoLib::Point*> *polygon_pnts(new std::vector<GeoLib::Point*>);
for (std::size_t k(0); k < polygon_in.getNumberOfPoints(); k++)
polygon_pnts->push_back (new GeoLib::Point (*(polygon_in.getPoint(k))));
// 2 rotate points
double d_polygon (0.0);
GeoLib::getNewellPlane (*polygon_pnts, plane_normal, d_polygon);
MathLib::DenseMatrix<double> rot_mat(3,3);
GeoLib::computeRotationMatrixToXY(plane_normal, rot_mat);
GeoLib::rotatePoints(rot_mat, *polygon_pnts);
// 3 set z coord to zero
std::for_each(polygon_pnts->begin(), polygon_pnts->end(),
[] (GeoLib::Point* p) { (*p)[2] = 0.0; }
);
// 4 create new polygon
GeoLib::Polyline rot_polyline(*polygon_pnts);
for (std::size_t k(0); k < polygon_in.getNumberOfPoints(); k++)
rot_polyline.addPoint(k);
rot_polyline.addPoint(0);
return GeoLib::Polygon(rot_polyline);
}
} // end namespace GeoLib } // end namespace GeoLib
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "Triangle.h" #include "Triangle.h"
#include "PointVec.h" #include "PointVec.h"
#include "Polygon.h"
namespace GeoLib namespace GeoLib
{ {
...@@ -280,6 +280,19 @@ double orientation3d(MathLib::Point3d const& p, ...@@ -280,6 +280,19 @@ double orientation3d(MathLib::Point3d const& p,
void computeAndInsertAllIntersectionPoints(GeoLib::PointVec &pnt_vec, void computeAndInsertAllIntersectionPoints(GeoLib::PointVec &pnt_vec,
std::vector<GeoLib::Polyline*> & plys); std::vector<GeoLib::Polyline*> & plys);
/**
* Function rotates a polygon to the xy plane. For this reason, (1) the points of
* the given polygon are copied, (2) a so called Newell plane is computed
* (getNewellPlane()) and the points are rotated, (3) for security the
* \f$z\f$ coordinates of the rotated points are set to zero and finally, (4) a
* new polygon is constructed using the rotated points.
* \see getNewellPlane()
* @param polygon_in a copy of the polygon_in polygon will be rotated
* @param plane_normal the normal of the original Newell plane
* @return a rotated polygon
*/
GeoLib::Polygon rotatePolygonToXY(GeoLib::Polygon const& polygon_in,
MathLib::Vector3 & plane_normal);
} // end namespace GeoLib } // end namespace GeoLib
......
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