GemaCoreLib
The GeMA Core library
Namespaces | Functions | Variables
gmGeometryUtils.cpp File Reference

Implementation of utilitary functions for working with geometry. More...

#include "gmGeometryUtils.h"
#include "gmCell.h"
#include "gmTrace.h"
#include <QtMath>
#include <float.h>
Include dependency graph for gmGeometryUtils.cpp:

Namespaces

 GmGeometryUtils
 Groups utilitary routines for working with geometry.
 

Functions

static double GmGeometryUtils::angleScore2D (const GmVector &a, const GmVector &b, const GmVector &c)
 Returns the angle score of the ca and cb vectors in 2D. If score is: More...
 
static double GmGeometryUtils::orientScore2D (const GmVector &a, const GmVector &b, const GmVector &c)
 Returns the orientation score of the a, b and c points in 2D. Returns a positive value if the points a, b and c are arranged in CCW order, a negative value if the points are in CW order, and zero if the points are collinear. A more common (but less symmetric) interpretation is that it returns a positive value if a lies to the left of the directed line bc (see https://people.eecs.berkeley.edu/~jrs/meshpapers/robnotes.pdf). Can be used in 3D but only x and y coordinates will be considered.
 
static double GmGeometryUtils::orientScore3D (const GmVector &a, const GmVector &b, const GmVector &c, const GmVector &d)
 Given four points a, b, c, and d, returns the signed volume of the parallelepiped determined by the vectors ad, bd and cd. It is positive if the points occur in the orientation illustrated in Figure 3 (see https://people.eecs.berkeley.edu/~jrs/meshpapers/robnotes.pdf), negative if they occur in the mirror-image orientation, and zero if the four points are coplanar. You can apply a right-hand rule : orient your right hand with fingers curled to follow the circular sequence bcd. If your thumb points toward a, a positive value is returned.
 
static bool GmGeometryUtils::sameSide3D (const GmVector &p, const GmVector &n, const GmVector &a, const GmVector &b)
 Returns true if points a and b are on the same side of plane defined by point p and normal n.
 
static bool GmGeometryUtils::sameSide3D (const GmVector &p1, const GmVector &p2, const GmVector &p3, const GmVector &a, const GmVector &b)
 Returns true if points a and b are on the same side of plane defined by points p1, p2 and p3.
 
static GmMatrix GmGeometryUtils::rotationMatrix (const GmVector &u, double angle)
 
double GmGeometryUtils::edgeLength (const GmVector &p1, const GmVector &p2)
 Calculates the length of the edge determined by points p1 and p2.
 
double GmGeometryUtils::triangleArea (const GmVector &p1, const GmVector &p2, const GmVector &p3)
 Calculates the area of the triangle determined by points p1, p2 and p3 (2D or 3D), organized in CCW order.
 
double GmGeometryUtils::quadArea (const GmVector &p1, const GmVector &p2, const GmVector &p3, const GmVector &p4)
 Calculates the area of a quad defined by points p1 to p4 (2D or 3D), defined in CCW order.
 
double GmGeometryUtils::hexahedronVolume (const GmVector &p1, const GmVector &p2, const GmVector &p3, const GmVector &p4, const GmVector &p5, const GmVector &p6, const GmVector &p7, const GmVector &p8)
 Calculates the volume of the given hexahedron. Points follow the standard Hex cell definition.
 
double GmGeometryUtils::tetrahedronVolume (const GmVector &p1, const GmVector &p2, const GmVector &p3, const GmVector &p4)
 Calculates the volume of the given tetrahedron. Points follow the standard Tet cell definition.
 
double GmGeometryUtils::wedgeVolume (const GmVector &p1, const GmVector &p2, const GmVector &p3, const GmVector &p4, const GmVector &p5, const GmVector &p6)
 Calculates the volume of the given wedge. Points follow the standard Wedge cell definition.
 
double GmGeometryUtils::pyramidVolume (const GmVector &p1, const GmVector &p2, const GmVector &p3, const GmVector &p4, const GmVector &p5)
 Calculates the volume of the given pyramid. Points follow the standard pyramid cell definition.
 
void GmGeometryUtils::edgeCentroid (const GmVector &p1, const GmVector &p2, GmVector &coord)
 Returns the cartesian coordinate of the edge centroid.
 
void GmGeometryUtils::triangleCentroid (const GmVector &p1, const GmVector &p2, const GmVector &p3, GmVector &coord)
 Returns the cartesian coordinate of the triangle centroid.
 
void GmGeometryUtils::quadCentroid (const GmVector &p1, const GmVector &p2, const GmVector &p3, const GmVector &p4, GmVector &coord)
 Returns the cartesian coordinate of the quad centroid.
 
void GmGeometryUtils::hexahedronCentroid (const GmVector &p1, const GmVector &p2, const GmVector &p3, const GmVector &p4, const GmVector &p5, const GmVector &p6, const GmVector &p7, const GmVector &p8, GmVector &coord)
 
void GmGeometryUtils::tetrahedronCentroid (const GmVector &p1, const GmVector &p2, const GmVector &p3, const GmVector &p4, GmVector &coord)
 Returns the cartesian coordinate of the tetrahedron centroid.
 
void GmGeometryUtils::wedgeCentroid (const GmVector &p1, const GmVector &p2, const GmVector &p3, const GmVector &p4, const GmVector &p5, const GmVector &p6, GmVector &coord)
 Returns the cartesian coordinate of the wedge centroid.
 
void GmGeometryUtils::pyramidCentroid (const GmVector &p1, const GmVector &p2, const GmVector &p3, const GmVector &p4, const GmVector &p5, GmVector &coord)
 Returns the cartesian coordinate of the pyramid centroid.
 
double GmGeometryUtils::intersectionLength (double a0, double a1, double b0, double b1)
 Intersection length between two intervals Positive for intervals intersecting, negative otherwise.
 
bool GmGeometryUtils::lineIntersection (GmVector &A, GmVector &B, GmVector &C, GmVector &D, double eps=1e-7)
 Returns true if the lines AB and CD intersect Assumes A, B, C and D are 2D, doesnt cosider the segments extreme points for intersection.
 
bool GmGeometryUtils::polygon2DIsSelfIntersecting (const GmMatrix &X)
 Returns true if the polygon delimited by the cell vertices is self-intersecting, or false otherwise. More...
 
bool GmGeometryUtils::polygon2DIsCCW (const GmMatrix &X)
 Returns true if the polygon delimited by the cell vertices is oriented CCW. More...
 
bool GmGeometryUtils::polygonIsConvex (const GmMatrix &X)
 Returns true if the polygon delimited by the cell vertices is convex, or false otherwise. More...
 
bool GmGeometryUtils::polygon3DIsPlanar (const GmMatrix &X, double tol)
 Returns true if the polygon delimited by the cell vertices is planar. More...
 
GmMatrix GmGeometryUtils::shuffle (const GmMatrix &X, const int order[], int size)
 Returns quad8 vertices in circular order. More...
 
bool GmGeometryUtils::tri3DIsColinear (const GmMatrix &X, double eps)
 
bool GmGeometryUtils::pointInConvexPolygon (const GmMatrix &X, const GmVector &p)
 Returns true if the point p is inside the polygon delimited by the cell vertices (convex hull), or false otherwise. More...
 
bool GmGeometryUtils::pointInTesselatedPolygon_T6 (const GmMatrix &X, const GmVector &p)
 Returns true if the point p is inside the tesselated T6 polygon or false otherwise. More...
 
bool GmGeometryUtils::pointInTesselatedPolygon_Q8 (const GmMatrix &X, const GmVector &p)
 Returns true if the point p is inside the tesselated Q8 polygon or false otherwise. More...
 
bool GmGeometryUtils::pointInPolygon (const GmMatrix &X, const GmCellGeometry &g, const GmVector &p)
 Returns true if the point p is inside the polygon delimited by the cell vertices, or false otherwise. More...
 
static bool GmGeometryUtils::pointInTetrahedron (const GmMatrix &X, const GmVector &p, QVector< bool > &ss)
 Helper function for pointInTetrahedron(X, p) also returning the "same side" vector.
 
bool GmGeometryUtils::pointInTetrahedron (const GmMatrix &X, const GmVector &p)
 Returns true if the point p is inside the tetrahedron, or false otherwise. The X matrix should be the node matrix for a GeMA TET4 element with nodes in columns.
 
bool GmGeometryUtils::pointInHexahedron (const GmMatrix &X, const GmVector &p)
 
bool GmGeometryUtils::isTriNormalOutward (const GmVector &p0, const GmVector &p1, const GmVector &p2, const GmVector &ref)
 
bool GmGeometryUtils::isQuadNormalOutward (const GmVector &p0, const GmVector &p1, const GmVector &p2, const GmVector &p3, const GmVector &ref)
 
bool GmGeometryUtils::hex8PlanarFaces (const GmMatrix &X, double tol)
 
bool GmGeometryUtils::hex8IsWellDefined (const GmMatrix &X)
 
void GmGeometryUtils::lineProjection (const GmVector &a, const GmVector &b, const GmVector &p, double *t, double *u)
 
template<int N>
bool GmGeometryUtils::checkQuadraticEdges (const GmMatrix &X, double proportion_max, int edges[N][3])
 
bool GmGeometryUtils::tet10ValidEdges (const GmMatrix &X, double proportion_max)
 
bool GmGeometryUtils::hex20ValidEdges (const GmMatrix &X, double proportion_max)
 Returns true if the points defined between the edges of hex20 follows: 1) Their projection to the 3d line containing the edge is within the edge, i.e., their parametrization is in (0,1) 2) The distance to the projection is not greater than a proportion of the edge length.
 
bool GmGeometryUtils::hex27ValidFacesCenter (const GmMatrix &X, double tol)
 Returns true if face center point is collinear with the face. Assumes that the quad faces are planar.
 
bool GmGeometryUtils::pyra5IsWellDefined (const GmMatrix &X, double tol)
 
bool GmGeometryUtils::pyra13ValidEdges (const GmMatrix &X, double proportion_max)
 
bool GmGeometryUtils::wedge6IsWellDefined (const GmMatrix &X, double tol)
 
bool GmGeometryUtils::wedge15ValidEdges (const GmMatrix &X, double proportion_max)
 
double GmGeometryUtils::pointToConvexPolygon (const GmMatrix &X, const GmVector &p, GmVector &proj)
 Returns the dquared distance of point p to the polygon delimited by the cell vertices (convex hull) and fills the coordinates of the corresponding projected point on cell. More...
 
double GmGeometryUtils::pointToTetrahedron (const GmMatrix &X, const GmVector &p, GmVector &proj)
 Returns the squared distance of point p to the tetrahedron delimited by its vertices and fills the coordinates of the corresponding projected point on tetrahedron. More...
 
bool GmGeometryUtils::tet4IsWellDefined (const GmVector &p1, const GmVector &p2, const GmVector &p3, const GmVector &p4)
 
bool GmGeometryUtils::isCoplanar3D (const GmVector &a, const GmVector &b, const GmVector &c, const GmVector &d, double tol)
 
void GmGeometryUtils::get2DPlaneRotationVectors (const GmVector &origin, const GmVector &v1, const GmVector &v2, GmVector &ix, GmVector &iy)
 
GmMatrix GmGeometryUtils::get2DProjectionMatCol (const GmMatrix &X)
 Returns a 2x3 rigid transform matrix taking v1-origin and v2-origin 3D vectors to the 2D xy plane.
 
GmMatrix GmGeometryUtils::get2DProjectionMatRow (const GmMatrix &X)
 Returns a 3x2 (transposed) rigid transform matrix taking v1-origin and v2-origin 3D vectors to the 2D xy plane.
 
QVector< QVector< int > > GmGeometryUtils::edgeFaceList (const QVector< QVector< int >> &faceEdgeList, int edgeCount)
 Returns a edgeFace Vector of faces indexed by edge Its input is the inverse map faceEdge Vector.
 

Variables

static int GmGeometryUtils::hex2tet [6][4]
 Returns true if the point p is inside the hexahedron, or false otherwise. The X matrix should be the node matrix for a GeMA HEX8 element with nodes in columns. More...
 

Detailed Description

Implementation of utilitary functions for working with geometry.

Author
Erwan Yann Renaut
Date
october, 2018