ug4
Math Utilities

Functions

int ug::BinomCoeff (int n, int k)
 Returns the BinomialCoefficient. More...
 
template<class vector_t >
bool ug::BoxBoundProbe (const vector_t &v, const vector_t &boxMin, const vector_t &boxMax)
 Returns true if the point lies inside or on the boundary of the box. More...
 
template<class vector_t >
bool ug::BoxBoxIntersection (const vector_t &box1Min, const vector_t &box1Max, const vector_t &box2Min, const vector_t &box2Max)
 checks whether two boxes intersect. More...
 
template<class vector_t >
void ug::CalculateCenter (vector_t &centerOut, const vector_t *pointSet, size_t numPoints)
 calculates the center of a point-set More...
 
void ug::CalculateCovarianceMatrix (matrix33 &matOut, const vector3 *pointSet, const vector3 &center, size_t numPoints)
 Calculates the covariance matrix of a given point-set. More...
 
number ug::CalculateHexahedronVolume (const vector3 &a, const vector3 &b, const vector3 &c, const vector3 &d, const vector3 &e, const vector3 &f, const vector3 &g, const vector3 &h)
 
number ug::CalculateOctahedronVolume (const vector3 &a, const vector3 &b, const vector3 &c, const vector3 &d, const vector3 &e, const vector3 &f)
 
number ug::CalculatePrismVolume (const vector3 &a, const vector3 &b, const vector3 &c, const vector3 &d, const vector3 &e, const vector3 &f)
 
number ug::CalculatePyramidVolume (const vector3 &a, const vector3 &b, const vector3 &c, const vector3 &d, const vector3 &e)
 
number ug::CalculateTetrahedronVolume (const vector3 &a, const vector3 &b, const vector3 &c, const vector3 &d)
 
template<class TNumber >
TNumber ug::clip (TNumber val, TNumber lowerBound, TNumber upperBound)
 clips a number to the given interval [lowerBound, upperBound]. More...
 
bool ug::ConstructOrthonormalSystem (matrix33 &matOut, const vector3 &v, size_t vColInd)
 constructs a orthonormal matrix given a vector in 3d. More...
 
template<class TNumber >
TNumber ug::deg_to_rad (TNumber deg)
 
number ug::DistanceLineToLine (const vector3 &a1, const vector3 &a2, const vector3 &b1, const vector3 &b2)
 calculates the distance between two 3d line segments More...
 
template<class vector_t >
number ug::DistancePointToLine (const vector_t &v, const vector_t &v1, const vector_t &v2)
 calculates the distance of a point to a line segment More...
 
template<class vector_t >
number ug::DistancePointToLine (number &tOut, const vector_t &v, const vector_t &v1, const vector_t &v2)
 
template<class vector_t >
number ug::DistancePointToPlane (const vector_t &v, const vector_t &p, const vector_t &n)
 Calculates the distance between the specified point and the plane. More...
 
template<class vector_t >
number ug::DistancePointToRay (const vector_t &v, const vector_t &from, const vector_t &dir)
 calculates the distance of a point to a ray More...
 
template<class vector_t >
number ug::DistancePointToRay (number &tOut, const vector_t &v, const vector_t &from, const vector_t &dir)
 
template<class vector_t >
number ug::DistancePointToTriangle (vector_t &vOut, number &bc1Out, number &bc2Out, const vector_t &p, const vector_t &v1, const vector_t &v2, const vector_t &v3, const vector_t &n)
 calculates the minimal distance of a point to a triangle.
More...
 
template<class vector_t >
number ug::DropAPerpendicular (vector_t &vOut, const vector_t &v, const vector_t &v0, const vector_t &v1)
 finds the projection of v onto the line defined by v0 and v1 More...
 
bool ug::FindClosestPlane (vector3 &centerOut, vector3 &normalOut, const vector3 *pointSet, size_t numPoints)
 Finds the plane which minimizes the distance to the given point set. More...
 
bool ug::FindNormal (vector3 &normOut, const vector3 &v)
 finds a normal to the given vector in 3d. More...
 
template<class vector_t >
number ug::GeometricApproximationDegree (vector_t &n1, vector_t &n2, vector_t &n3, vector_t &tn)
 the returned degree lies between 0 and 1. The closer to 1 the better. More...
 
template<class vector_t >
bool ug::LineBoxIntersection (const vector_t &v1, const vector_t &v2, const vector_t &boxMin, const vector_t &boxMax)
 checks whether the given line-segment (v1, v2) intersect the given box. More...
 
template<class vector_t >
bool ug::LineLineIntersection2d (vector_t &vOut, number &t0Out, number &t1Out, const vector_t &from0, const vector_t &to0, const vector_t &from1, const vector_t &to1, const number threshold=0)
 calculates the intersection of a two lines in 2d More...
 
bool ug::LineLineIntersection3d (vector3 &aOut, vector3 &bOut, const vector3 &a1, const vector3 &a2, const vector3 &b1, const vector3 &b2)
 intersects two 3d line segments More...
 
template<class vector_t >
bool ug::LineLineProjection (number &t1Out, number &t2Out, const vector_t &a1, const vector_t &a2, const vector_t &b1, const vector_t &b2)
 calculates the closest point between the rays through the given lines. More...
 
template<class vector_t >
int ug::LineSphereIntersection (number &s1Out, number &s2Out, const vector_t &v1, const vector_t &v2, const vector_t &center, number radius)
 
template<class vector_t >
bool ug::PointIsInsideQuadrilateral (const vector_t &v, const vector_t &v0, const vector_t &v1, const vector_t &v2, const vector_t &v3)
 Returns true if the point lies inside or on the boundary of a quadrilateral. More...
 
template<class vector_t >
bool ug::PointIsInsideTetrahedron (const vector_t &v, const vector_t &v0, const vector_t &v1, const vector_t &v2, const vector_t &v3)
 Returns true if the point lies inside or on the boundary of a tetrahedron. More...
 
template<class vector_t >
bool ug::PointIsInsideTriangle (const vector_t &v, const vector_t &v0, const vector_t &v1, const vector_t &v2)
 Returns true if the point lies inside or on the boundary of a triangle. More...
 
template<class vector_t >
bool ug::PointIsInsideTriangle_HighAcc (const vector_t &v, const vector_t &v0, const vector_t &v1, const vector_t &v2)
 Returns true if the point lies inside or on a side of the given triangle. More...
 
template<class vector_t >
vector_t ug::PointOnRay (const vector_t &from, const vector_t &dir, number s)
 returns the point described by a relative ray coordinate More...
 
template<class vector_t >
number ug::ProjectPointToLine (vector_t &vOut, const vector_t &v, const vector_t &from, const vector_t &to)
 finds the projection of v onto the line defined by from and to More...
 
template<class vector_t >
void ug::ProjectPointToPlane (vector_t &vOut, const vector_t &v, const vector_t &p, const vector_t &n)
 projects v onto the plane defined by the point p and the planes normal n. More...
 
template<class vector_t >
number ug::ProjectPointToRay (vector_t &vOut, const vector_t &v, const vector_t &from, const vector_t &dir)
 finds the projection of v onto the ray defined by from and dir More...
 
template<class vector_t >
number ug::QuadrilateralArea (const vector_t &p1, const vector_t &p2, const vector_t &p3, const vector_t &p4)
 calculates the are of the triangle defined by p1, p2 and p3 More...
 
template<class TNumber >
TNumber ug::rad_to_deg (TNumber rad)
 
template<class vector_t >
bool ug::RayBoxIntersection (const vector_t &rayFrom, const vector_t &rayDir, const vector_t &boxMin, const vector_t &boxMax, number *tNearOut=NULL, number *tFarOut=NULL)
 checks if a ray is intersecting a box More...
 
bool ug::RayCylinderIntersection (number &tMinOut, number &tMaxOut, const vector3 &rayFrom, const vector3 &rayDir, const vector3 &cylCenter, const vector3 &cylAxis, number cylRadius)
 returns the parameter values at which a given ray intersects an infinite cylinder. More...
 
template<class vector_t >
bool ug::RayLineIntersection2d (vector_t &vOut, number &bcOut, number &tOut, const vector_t &p0, const vector_t &p1, const vector_t &vFrom, const vector_t &vDir, number sml=0)
 calculates the intersection of a ray with a Line in 2d More...
 
template<class vector_t >
bool ug::RayPlaneIntersection (vector_t &vOut, number &tOut, const vector_t &rayFrom, const vector_t &rayDir, const vector_t &p, const vector_t &n)
 calculates the intersection of the ray rayFrom+t*rayDir and the plane (x-p)*n=0. More...
 
template<class vector_t >
bool ug::RayRayIntersection2d (vector_t &vOut, number &t0Out, number &t1Out, const vector_t &p0, const vector_t &dir0, const vector_t &p1, const vector_t &dir1)
 calculates the intersection of two Rays in 2d More...
 
bool ug::RayRayIntersection3d (vector3 &aOut, vector3 &bOut, const vector3 &p0, const vector3 &dir0, const vector3 &p1, const vector3 &dir1)
 intersects two 3d rays More...
 
template<class vector_t >
bool ug::RayRayProjection (number &t1Out, number &t2Out, const vector_t &from1, const vector_t &dir1, const vector_t &from2, const vector_t &dir2)
 Calculates the parameter values at wich two rays are closest. More...
 
template<class vector_t >
int ug::RaySphereIntersection (number &s1Out, number &s2Out, const vector_t &v, const vector_t &dir, const vector_t &center, number radius)
 checks whether the line segment (v1, v2) intersect the given sphere. More...
 
template<class vector_t >
bool ug::RayTriangleIntersection (vector_t &vOut, const vector_t &p0, const vector_t &p1, const vector_t &p2, const vector_t &vFrom, const vector_t &vDir)
 calculates the intersection of a ray with a triangle More...
 
template<class vector_t >
bool ug::RayTriangleIntersection (vector_t &vOut, number &bc1Out, number &bc2Out, number &tOut, const vector_t &p0, const vector_t &p1, const vector_t &p2, const vector_t &vFrom, const vector_t &vDir, const number small=SMALL)
 calculates the intersection of a ray with a triangle More...
 
template<class vector_t >
void ug::ReflectVectorAtPlane (vector_t &vReflectedOut, const vector_t &v, const vector_t &n, const vector_t &r0)
 reflects a vector at a plane More...
 
template<class TNumber >
TNumber ug::sq (TNumber val)
 returns the square of a value (val*val) More...
 
bool ug::TransformPointSetTo2D (vector2 *pointSetOut, const vector3 *pointSet, size_t numPoints)
 transforms points from 3d space to 2d space. More...
 
template<class vector_t >
number ug::TriangleArea (const vector_t &p1, const vector_t &p2, const vector_t &p3)
 calculates the are of the triangle defined by p1, p2 and p3 More...
 
template<class vector_t >
vector_t ug::TriangleBarycenter (const vector_t &p1, const vector_t &p2, const vector_t &p3)
 Calculates the barycenter of a triangle (1/3) * (p1+p2+p3) More...
 
UG_API bool ug::TriangleBoxIntersection (const MathVector< 3 > &p0, const MathVector< 3 > &p1, const MathVector< 3 > &p2, const MathVector< 3 > &boxMin, const MathVector< 3 > &boxMax)
 checks whether a triangle and an axis-aligned box intersect. More...
 
template<class vector_t >
number ug::TriangleQuality_Area (const vector_t &p1, const vector_t &p2, const vector_t &p3)
 returns a value between 0 and 1. The higher the better. More...
 
UG_API bool ug::TriangleTriangleIntersection (const MathVector< 3 > &p0, const MathVector< 3 > &p1, const MathVector< 3 > &p2, const MathVector< 3 > &q0, const MathVector< 3 > &q1, const MathVector< 3 > &q2, MathVector< 3 > *ip1Out=NULL, MathVector< 3 > *ip2Out=NULL, number snapThreshold=SMALL)
 checks whether two triangles intersect and returns the intervals, if they do. More...
 
template<class TNumber >
TNumber ug::urand (TNumber lowerBound, TNumber upperBound)
 uniform distributed random numbers in [lowerBound, upperBound[. Use srand to set a seed. More...
 
bool ug::TriangleCircumcenter (vector2 &centerOut, const vector2 &p1, const vector2 &p2, const vector2 &p3)
 Calculates the circumcenter of a triangle. More...
 
bool ug::TriangleCircumcenter (vector3 &centerOut, const vector3 &p1, const vector3 &p2, const vector3 &p3)
 Calculates the circumcenter of a triangle. More...
 

Detailed Description

Function Documentation

◆ BinomCoeff()

◆ BoxBoundProbe()

template<class vector_t >
bool ug::BoxBoundProbe ( const vector_t &  v,
const vector_t &  boxMin,
const vector_t &  boxMax 
)

Returns true if the point lies inside or on the boundary of the box.

v.size() has to be the same or less than boxMin.size() and boxMax.size(). If this condition is met, the method supports vectors of arbitrary dimension.

Referenced by ug::AABox< vector_t >::contains_point(), ug::node_tree::CreateSubOctrees(), ug::node_tree::Traverser_ProjectPoint::handle_boxed_group(), ug::RayBoxIntersection(), and ug::TriangleFill().

◆ BoxBoxIntersection()

template<class vector_t >
bool ug::BoxBoxIntersection ( const vector_t &  box1Min,
const vector_t &  box1Max,
const vector_t &  box2Min,
const vector_t &  box2Max 
)

checks whether two boxes intersect.

Make sure that all parameters have the same size.

Referenced by ug::node_tree::Traverser_ProjectPoint::handle_boxed_group(), and ug::AABox< vector_t >::overlaps_line().

◆ CalculateCenter()

◆ CalculateCovarianceMatrix()

UG_API void ug::CalculateCovarianceMatrix ( matrix33 matOut,
const vector3 pointSet,
const vector3 center,
size_t  numPoints 
)

Calculates the covariance matrix of a given point-set.

Please note that you have to specify the point-set together with its center-point.

Referenced by ug::FindClosestPlane().

◆ CalculateHexahedronVolume()

number ug::CalculateHexahedronVolume ( const vector3 a,
const vector3 b,
const vector3 c,
const vector3 d,
const vector3 e,
const vector3 f,
const vector3 g,
const vector3 h 
)

◆ CalculateOctahedronVolume()

number ug::CalculateOctahedronVolume ( const vector3 a,
const vector3 b,
const vector3 c,
const vector3 d,
const vector3 e,
const vector3 f 
)

(compare to lib_disc/common/geometry_util.h) This function returns the volume of an octhedron in 3d by calculating the volumes of the upper and lower pyramid the octahedron consists of. The pyramidal volumes are computed via: V = 1/3 * (S * h) with

  • S is the area of the base
  • h is the height

The corner coordinates must be given as prescribed by the reference element

Parameters
[in]a,...,f3d Vectors of corner coordinates (6 corners)
Returns
number Volume of Octahedron

References ug::VecCross(), ug::VecDot(), and ug::VecSubtract().

Referenced by ug::CalculateVolume().

◆ CalculatePrismVolume()

number ug::CalculatePrismVolume ( const vector3 a,
const vector3 b,
const vector3 c,
const vector3 d,
const vector3 e,
const vector3 f 
)

◆ CalculatePyramidVolume()

number ug::CalculatePyramidVolume ( const vector3 a,
const vector3 b,
const vector3 c,
const vector3 d,
const vector3 e 
)

◆ CalculateTetrahedronVolume()

UG_API number ug::CalculateTetrahedronVolume ( const vector3 a,
const vector3 b,
const vector3 c,
const vector3 d 
)

◆ clip()

template<class TNumber >
TNumber ug::clip ( TNumber  val,
TNumber  lowerBound,
TNumber  upperBound 
)

clips a number to the given interval [lowerBound, upperBound].

◆ ConstructOrthonormalSystem()

UG_API bool ug::ConstructOrthonormalSystem ( matrix33 matOut,
const vector3 v,
size_t  vColInd 
)

constructs a orthonormal matrix given a vector in 3d.

Given a vector in 3d, this method constructs an orthonormal system. The given vector correspond to one of the matrix columns, the others are found so that matOut is orthonormal (inv(matOut) == trans(matOut)). Please note that matOut is not unique.

This method assumes that the matrix is accessed as follows: m[colInd][rowInd].

Parameters
matOutMatrix
vvector
vColIndspecifies in which column to put v.

References ug::FindNormal(), ug::VecCross(), and ug::VecNormalize().

Referenced by ug::IntersectCoplanarTriangles(), and ug::TransformPointSetTo2D().

◆ deg_to_rad()

◆ DistanceLineToLine()

UG_API number ug::DistanceLineToLine ( const vector3 a1,
const vector3 a2,
const vector3 b1,
const vector3 b2 
)

calculates the distance between two 3d line segments

Calculates the distance between the two finite line segments a (given by endpoints a1, a2) and b (given by endpoints b1, b2).

This method internally uses the IntersectLineSegments algorithm by Graham Rhodes. Please have a look at lineintersect_utils.h for more information.

References IntersectLineSegments(), ug::SMALL, and ug::VecLength().

Referenced by ug::IsSliver().

◆ DistancePointToLine() [1/2]

template<class vector_t >
number ug::DistancePointToLine ( const vector_t &  v,
const vector_t &  v1,
const vector_t &  v2 
)
inline

calculates the distance of a point to a line segment

Referenced by ug::node_tree::Traverser_ProjectPoint::handle_collision_edges(), and ug::QualityGridGeneration().

◆ DistancePointToLine() [2/2]

template<class vector_t >
number ug::DistancePointToLine ( number tOut,
const vector_t &  v,
const vector_t &  v1,
const vector_t &  v2 
)

◆ DistancePointToPlane()

template<class vector_t >
number ug::DistancePointToPlane ( const vector_t &  v,
const vector_t &  p,
const vector_t &  n 
)

Calculates the distance between the specified point and the plane.

References p, ug::ProjectPointToPlane(), and ug::VecDistance().

Referenced by ug::CalculateMinVolumeHeight(), ug::CalculatePyramidVolume(), ug::CutEdgesWithPlane(), and ug::ResolveTriangleIntersections().

◆ DistancePointToRay() [1/2]

template<class vector_t >
number ug::DistancePointToRay ( const vector_t &  v,
const vector_t &  from,
const vector_t &  dir 
)
inline

◆ DistancePointToRay() [2/2]

template<class vector_t >
number ug::DistancePointToRay ( number tOut,
const vector_t &  v,
const vector_t &  from,
const vector_t &  dir 
)
inline

◆ DistancePointToTriangle()

template<class vector_t >
number ug::DistancePointToTriangle ( vector_t &  vOut,
number bc1Out,
number bc2Out,
const vector_t &  p,
const vector_t &  v1,
const vector_t &  v2,
const vector_t &  v3,
const vector_t &  n 
)

calculates the minimal distance of a point to a triangle.

Distance is measured between the point p and the point on the triangle which is closest to p.

The triangle is defined by the three corner-points v1, v2 and v3.

n specifies the normal of the triangle. It does not have do be normalized.

The closest point on the triangle is written to vOut. Its barycentric coordinate is written to bc1Out and bc2Out.

The method returns the minimal distance of the point to the triangle.

References ug::DistancePointToRay(), p, ug::RayTriangleIntersection(), ug::VecDistance(), and ug::VecSubtract().

Referenced by ug::node_tree::Traverser_ProjectPoint::handle_collision_triangles(), and ug::ProjectPointToSurface().

◆ DropAPerpendicular()

template<class vector_t >
number ug::DropAPerpendicular ( vector_t &  vOut,
const vector_t &  v,
const vector_t &  v0,
const vector_t &  v1 
)

finds the projection of v onto the line defined by v0 and v1

projects v onto the line defined by v0 and v1. The projected point is returned in vOut.

returns s so that vOut = (1.0-s)*v0 + s*v1

References s, ug::SMALL, ug::VecAdd(), ug::VecDot(), ug::VecScale(), and ug::VecSubtract().

Referenced by ug::CalculateCreaseNormal(), ug::CalculateOuterNormal(), ug::DistancePointToLine(), and ug::ResolveVertexEdgeIntersection().

◆ FindClosestPlane()

UG_API bool ug::FindClosestPlane ( vector3 centerOut,
vector3 normalOut,
const vector3 pointSet,
size_t  numPoints 
)

Finds the plane which minimizes the distance to the given point set.

The method returns the true if the calculation was a success and false if not. If true is returned, then centerOut and normalOut will contain the center and the normal of the plane which minimizes the distance to the given point set.

References ug::CalculateCenter(), ug::CalculateCovarianceMatrix(), ug::CalculateEigenvalues(), and ug::VecNormalize().

Referenced by ug::TransformPointSetTo2D().

◆ FindNormal()

UG_API bool ug::FindNormal ( vector3 normOut,
const vector3 v 
)

finds a normal to the given vector in 3d.

References ug::VecDot(), ug::VecNormalize(), ug::VecScale(), and ug::VecSubtract().

Referenced by ug::ConstructOrthonormalSystem().

◆ GeometricApproximationDegree()

template<class vector_t >
number ug::GeometricApproximationDegree ( vector_t &  n1,
vector_t &  n2,
vector_t &  n3,
vector_t &  tn 
)

the returned degree lies between 0 and 1. The closer to 1 the better.

returns the minimal dot-product of each normal of the triangle-corners with the triangles normal.

References ug::VecDot().

Referenced by ug::TryCollapse().

◆ LineBoxIntersection()

template<class vector_t >
bool ug::LineBoxIntersection ( const vector_t &  v1,
const vector_t &  v2,
const vector_t &  boxMin,
const vector_t &  boxMax 
)

checks whether the given line-segment (v1, v2) intersect the given box.

vector_t has to feature a static 'Size' member and index access

See also
RayBoxIntersection

References ug::RayBoxIntersection(), and ug::VecSubtract().

Referenced by ug::node_tree::CreateSubOctrees().

◆ LineLineIntersection2d()

template<class vector_t >
bool ug::LineLineIntersection2d ( vector_t &  vOut,
number t0Out,
number t1Out,
const vector_t &  from0,
const vector_t &  to0,
const vector_t &  from1,
const vector_t &  to1,
const number  threshold = 0 
)

calculates the intersection of a two lines in 2d

The lines are specified through their endpoints: (from0, to0) describes the first line, (from1, to1) the second line.

If the method succeeds (the lines intersects) the methods returns true and writes the position of the intersection to vOut. t0Out and t1Out will contain the local coordinate of the intersection regarding the lines parameter form.

References ug::RayRayIntersection2d(), and ug::VecSubtract().

Referenced by ug::IntersectCoplanarTriangles().

◆ LineLineIntersection3d()

UG_API bool ug::LineLineIntersection3d ( vector3 aOut,
vector3 bOut,
const vector3 a1,
const vector3 a2,
const vector3 b1,
const vector3 b2 
)

intersects two 3d line segments

Returns true, if the lines intersect. If they don't, the output parameters are filled with the points, at which the lines have the minimal distance. Specify lines a (given by endpoints a1, a2) and b (given by endpoints b1, b2).

Output-parameters: aOut, bOut represent the closest points on the two lines.

This method internally uses the IntersectLineSegments algorithm by Graham Rhodes. Please have a look at lineintersect_utils.h for more information.

References IntersectLineSegments(), and ug::SMALL.

◆ LineLineProjection()

template<class vector_t >
bool ug::LineLineProjection ( number t1Out,
number t2Out,
const vector_t &  a1,
const vector_t &  a2,
const vector_t &  b1,
const vector_t &  b2 
)

calculates the closest point between the rays through the given lines.

returns true if the closest points lie inside the line segments.

References ug::RayRayProjection(), and ug::VecSubtract().

Referenced by ug::ResolveEdgeEdgeIntersection().

◆ LineSphereIntersection()

template<class vector_t >
int ug::LineSphereIntersection ( number s1Out,
number s2Out,
const vector_t &  v1,
const vector_t &  v2,
const vector_t &  center,
number  radius 
)

◆ PointIsInsideQuadrilateral()

template<class vector_t >
bool ug::PointIsInsideQuadrilateral ( const vector_t &  v,
const vector_t &  v0,
const vector_t &  v1,
const vector_t &  v2,
const vector_t &  v3 
)

Returns true if the point lies inside or on the boundary of a quadrilateral.

This method should only be used if v, v0, v1, v2, and v3 do lie in the same x-y-plane.

References ug::SMALL, ug::VecDot(), ug::VecSubtract(), and ug::VecTwoNormSq().

Referenced by ug::ContainsPoint().

◆ PointIsInsideTetrahedron()

template<class vector_t >
bool ug::PointIsInsideTetrahedron ( const vector_t &  v,
const vector_t &  v0,
const vector_t &  v1,
const vector_t &  v2,
const vector_t &  v3 
)

Returns true if the point lies inside or on the boundary of a tetrahedron.

This method does not care about the orientation of the tetrahedron. This however makes it a little slower than a method that only works for correctly orientated tetrahedrons.

References ug::SMALL, ug::VecCross(), ug::VecDot(), ug::VecSubtract(), and ug::VecTwoNormSq().

Referenced by ug::PointIsInsideTetrahedron(), ug::SeparateRegions(), and ug::TetReferenceMappingTest().

◆ PointIsInsideTriangle()

template<class vector_t >
bool ug::PointIsInsideTriangle ( const vector_t &  v,
const vector_t &  v0,
const vector_t &  v1,
const vector_t &  v2 
)

Returns true if the point lies inside or on the boundary of a triangle.

This method should only be used if v, v0, v1, and v2 do lie in the same x-y-plane.

References ug::SMALL, ug::VecDot(), ug::VecSubtract(), and ug::VecTwoNormSq().

Referenced by ug::ContainsPoint(), ug::IntersectCoplanarTriangles(), ug::PointIsInsideTriangle_HighAcc(), and ug::TriangleFill().

◆ PointIsInsideTriangle_HighAcc()

template<class vector_t >
bool ug::PointIsInsideTriangle_HighAcc ( const vector_t &  v,
const vector_t &  v0,
const vector_t &  v1,
const vector_t &  v2 
)

Returns true if the point lies inside or on a side of the given triangle.

This method should only be used if v, v0, v1, and v2 do lie in the same x-y-plane.

The method has a higher accuracy than PointIsInsideTriangle, however it also has a higher performance overhead.

References ug::PointIsInsideTriangle().

◆ PointOnRay()

template<class vector_t >
vector_t ug::PointOnRay ( const vector_t &  from,
const vector_t &  dir,
number  s 
)

returns the point described by a relative ray coordinate

References s.

Referenced by ug::OverlyingSubsetFinder< TDomain >::findOverlyingSubset(), ug::ZRayTracer< TDomain >::get_min_at(), and ug::DomainRayTracer::trace_ray().

◆ ProjectPointToLine()

template<class vector_t >
number ug::ProjectPointToLine ( vector_t &  vOut,
const vector_t &  v,
const vector_t &  from,
const vector_t &  to 
)

finds the projection of v onto the line defined by from and to

projects v onto the line defined by from and to. The projected point is returned in vOut.

returns s so that vOut = from + s * (to-from)

References ug::ProjectPointToRay(), and ug::VecSubtract().

Referenced by ug::ProjectVerticesToCloseEdges(), and ug::ResolveVertexFaceIntersection().

◆ ProjectPointToPlane()

template<class vector_t >
void ug::ProjectPointToPlane ( vector_t &  vOut,
const vector_t &  v,
const vector_t &  p,
const vector_t &  n 
)

projects v onto the plane defined by the point p and the planes normal n.

The result is written to vOut.

References p, ug::VecDot(), ug::VecNormalize(), ug::VecScale(), and ug::VecSubtract().

Referenced by ug::DistancePointToPlane(), ug::ExpandFractures3d(), ug::ResolveVertexFaceIntersection(), ug::TangentialSmooth(), and ug::TangentialSmoothSimple().

◆ ProjectPointToRay()

template<class vector_t >
number ug::ProjectPointToRay ( vector_t &  vOut,
const vector_t &  v,
const vector_t &  from,
const vector_t &  dir 
)

finds the projection of v onto the ray defined by from and dir

projects v onto the ray defined by from and dir. The projected point is returned in vOut.

returns s so that vOut = from + s*dir

References s, ug::SMALL, ug::VecAdd(), ug::VecDot(), ug::VecScale(), and ug::VecSubtract().

Referenced by ug::AdaptSurfaceGridToCylinder(), ug::DistancePointToRay(), ug::CylinderProjector::perform_projection(), ug::SomaProjector::perform_projection(), ug::ProjectPointToLine(), ug::RaySphereIntersection(), ug::SpacialVertexSort(), and ug::TriangleCircumcenter().

◆ QuadrilateralArea()

template<class vector_t >
number ug::QuadrilateralArea ( const vector_t &  p1,
const vector_t &  p2,
const vector_t &  p3,
const vector_t &  p4 
)

calculates the are of the triangle defined by p1, p2 and p3

References ug::TriangleArea().

Referenced by ug::QuadrilateralAspectRatio().

◆ rad_to_deg()

template<class TNumber >
TNumber ug::rad_to_deg ( TNumber  rad)
inline

References ug::PI.

Referenced by ug::CheckDirection(), and ug::QualityGridGeneration().

◆ RayBoxIntersection()

template<class vector_t >
bool ug::RayBoxIntersection ( const vector_t &  rayFrom,
const vector_t &  rayDir,
const vector_t &  boxMin,
const vector_t &  boxMax,
number tNearOut = NULL,
number tFarOut = NULL 
)

checks if a ray is intersecting a box

vector_t has to feature a static 'Size' member and index access

Parameters
rayFrom
rayDir
boxMin
boxMax
tNearOutcan be NULL
tFarOutcan be NULL
See also
LineBoxIntersection

References ug::BoxBoundProbe(), and ug::SMALL.

Referenced by ug::LineBoxIntersection(), and ug::lg_ntree_traits_base< tree_dim, world_dim, elem_t_, common_data_t_ >::ray_box_intersection().

◆ RayCylinderIntersection()

UG_API bool ug::RayCylinderIntersection ( number tMinOut,
number tMaxOut,
const vector3 rayFrom,
const vector3 rayDir,
const vector3 cylCenter,
const vector3 cylAxis,
number  cylRadius 
)

returns the parameter values at which a given ray intersects an infinite cylinder.

References ug::RayRayIntersection3d(), ug::SMALL, ug::VecDistance(), ug::VecDot(), ug::VecLength(), ug::VecNormalize(), ug::VecScale(), and ug::VecSubtract().

Referenced by ug::AdaptSurfaceGridToCylinder(), and ug::CylinderCutProjector::new_vertex().

◆ RayLineIntersection2d()

template<class vector_t >
bool ug::RayLineIntersection2d ( vector_t &  vOut,
number bcOut,
number tOut,
const vector_t &  p0,
const vector_t &  p1,
const vector_t &  vFrom,
const vector_t &  vDir,
number  sml = 0 
)

calculates the intersection of a ray with a Line in 2d

You have to pass the line corners through p0 and p1 together with a point on the ray (vFrom) and the rays direction (vDir).

If the method succeeds (the ray intersects the line) the methods returns true and writes the position of the intersection to vOut. Furthermore the local (barycentric) coordinate of the intersection is written to bcOut. tOut will contain the local coordinate of the intersection regarding the rays parameter form.

References ug::RayRayIntersection2d(), and ug::VecSubtract().

Referenced by ug::ElementSideRayIntersectionWrapper< TRefElem, 2, 2 >::apply(), ug::SCVFofSCVRayIntersectionWrapper< 2, 2 >::apply(), and ug::RayElementIntersection().

◆ RayPlaneIntersection()

template<class vector_t >
bool ug::RayPlaneIntersection ( vector_t &  vOut,
number tOut,
const vector_t &  rayFrom,
const vector_t &  rayDir,
const vector_t &  p,
const vector_t &  n 
)

◆ RayRayIntersection2d()

template<class vector_t >
bool ug::RayRayIntersection2d ( vector_t &  vOut,
number t0Out,
number t1Out,
const vector_t &  p0,
const vector_t &  dir0,
const vector_t &  p1,
const vector_t &  dir1 
)

calculates the intersection of two Rays in 2d

If the two rays intersect (are not parallel), the method returns true. It writes its results to the parameters vOut (intersection point), t0Out (vOut = p0 + t0Out * dir0) and t1Out (vOut = p1 + t1Out * dir1).

You have to specify a point of each ray (p0 and p1) and the directions of each ray (dir0 and dir1).

References ug::Determinant(), ug::Inverse(), ug::MatVecMult(), ug::VecScaleAppend(), and ug::VecSubtract().

Referenced by ug::LineLineIntersection2d(), ug::RayLineIntersection2d(), and ug::TriangleCircumcenter().

◆ RayRayIntersection3d()

UG_API bool ug::RayRayIntersection3d ( vector3 aOut,
vector3 bOut,
const vector3 p0,
const vector3 dir0,
const vector3 p1,
const vector3 dir1 
)

intersects two 3d rays

Returns true, if the rays intersect. If they don't, the output parameters are filled with the points, at which the rays have the minimal distance. Specify each ray by one point on the ray (p0 and p1) and the direction of the ray (dir0 and dir1).

Output-parameters: aOut, bOut represent the closest points on the two rays.

This method internally uses the IntersectLineSegments algorithm by Graham Rhodes. Please have a look at lineintersect_utils.h for more information.

References IntersectLineSegments(), ug::SMALL, and ug::VecAdd().

Referenced by ug::RayCylinderIntersection().

◆ RayRayProjection()

template<class vector_t >
bool ug::RayRayProjection ( number t1Out,
number t2Out,
const vector_t &  from1,
const vector_t &  dir1,
const vector_t &  from2,
const vector_t &  dir2 
)

Calculates the parameter values at wich two rays are closest.

Returns true if the calculation was successfull (e.g. if the rays were not parallel).

See also
RayRayIntersection2d, RayRayIntersection3d, LineLineProjection

References ug::SMALL, ug::SMALL_SQ, ug::VecDot(), and ug::VecSubtract().

Referenced by ug::LineLineProjection().

◆ RaySphereIntersection()

template<class vector_t >
int ug::RaySphereIntersection ( number s1Out,
number s2Out,
const vector_t &  v,
const vector_t &  dir,
const vector_t &  center,
number  radius 
)

checks whether the line segment (v1, v2) intersect the given sphere.

The function returns the number of intersections and the values of s at which the line segment intersects.

References p, ug::ProjectPointToRay(), s, ug::SMALL, ug::VecDistance(), and ug::VecLength().

Referenced by ug::LineSphereIntersection(), and ug::ProjectVerticesToSphere().

◆ RayTriangleIntersection() [1/2]

template<class vector_t >
bool ug::RayTriangleIntersection ( vector_t &  vOut,
const vector_t &  p0,
const vector_t &  p1,
const vector_t &  p2,
const vector_t &  vFrom,
const vector_t &  vDir 
)
inline

calculates the intersection of a ray with a triangle

vector_t has to feature a x, y and z component.

You have to pass the triangles corners through p0, p1, p2 together with a point on the ray (vFrom) and the rays direction (vDir).

If the method succeeds (the ray intersects the triangle) the methods returns true and writes the position of the intersection to vOut.

References ug::RayTriangleIntersection(), and s.

◆ RayTriangleIntersection() [2/2]

template<class vector_t >
bool ug::RayTriangleIntersection ( vector_t &  vOut,
number bc1Out,
number bc2Out,
number tOut,
const vector_t &  p0,
const vector_t &  p1,
const vector_t &  p2,
const vector_t &  vFrom,
const vector_t &  vDir,
const number  small = SMALL 
)

calculates the intersection of a ray with a triangle

vector_t has to feature a x, y and z component.

You have to pass the triangles corners through p0, p1, p2 together with a point on the ray (vFrom) and the rays direction (vDir).

If the method succeeds (the ray intersects the triangle) the methods returns true and writes the position of the intersection to vOut. Furthermore the local (barycentric) coordinates of the intersection are written to bc1Out and bc2Out. tOut will contain the local coordinate of the intersection regarding the rays parameter form.

Referenced by ug::ElementSideRayIntersectionWrapper< TRefElem, 3, 3 >::apply(), ug::DistancePointToTriangle(), ug::RayElementIntersection(), ug::RayTriangleIntersection(), ug::ResolveEdgeFaceIntersection(), ug::ResolveVertexFaceIntersection(), ug::Valence3VertexIsObsolete(), and ug::Valence4VertexIsObsolete().

◆ ReflectVectorAtPlane()

template<class vector_t >
void ug::ReflectVectorAtPlane ( vector_t &  vReflectedOut,
const vector_t &  v,
const vector_t &  n,
const vector_t &  r0 
)

reflects a vector at a plane

This method reflects a given vector at a plane specified by n and r0, i.e. the plane P is given such that for all \( \vec{x} in P \) it holds that

\[ (\vec{x} - \vec{r0}) \cdot \vec{n} = 0. \]

Parameters
vReflectedOutthe reflected vector
vthe original vector, that is reflected
nnormal for plane specification
r0root point of plane

References s, ug::VecDot(), and ug::VecScaleAdd().

◆ sq()

◆ TransformPointSetTo2D()

UG_API bool ug::TransformPointSetTo2D ( vector2 pointSetOut,
const vector3 pointSet,
size_t  numPoints 
)

transforms points from 3d space to 2d space.

This method calculates the plane that minimizes the distances between the points and the plane. It then transforms all points to 2d so that the normal of the new min-distance-plane would point along the z-axis. It the projects all points onto the x-y-plane using the trivial projection.

Parameters
pointSetOutAn array of 2d-points of size numPoints.
pointSetAn array of 3d-points of size numPoints.
numPointsSpecifies the size of the point sets.

References ug::ConstructOrthonormalSystem(), ug::FindClosestPlane(), ug::TransposedMatVecMult(), and ug::VecSubtract().

Referenced by ug::grid_intersection_impl::DebugSave2d(), ug::TriangleFill(), and ug::TriangleFill_SweepLine().

◆ TriangleArea()

template<class vector_t >
number ug::TriangleArea ( const vector_t &  p1,
const vector_t &  p2,
const vector_t &  p3 
)

◆ TriangleBarycenter()

template<class vector_t >
vector_t ug::TriangleBarycenter ( const vector_t &  p1,
const vector_t &  p2,
const vector_t &  p3 
)

Calculates the barycenter of a triangle (1/3) * (p1+p2+p3)

References ug::VecScaleAdd().

◆ TriangleBoxIntersection()

bool ug::TriangleBoxIntersection ( const MathVector< 3 > &  p0,
const MathVector< 3 > &  p1,
const MathVector< 3 > &  p2,
const MathVector< 3 > &  boxMin,
const MathVector< 3 > &  boxMax 
)

checks whether a triangle and an axis-aligned box intersect.

Parameters
p0,p1,p2the corners of the triangle.
boxMinhas to contain the minimal-coordinates of the box.
boxMaxhas to contain the maximal-coordinates of the box.

References INSIDE, ug::TRI::m_P, ug::TriCubeIntersection(), and ug::VecSubtract().

Referenced by ug::node_tree::CreateSubOctrees(), and ug::node_tree::Traverser_IntersectFaces::handle_boxed_group().

◆ TriangleCircumcenter() [1/2]

UG_API bool ug::TriangleCircumcenter ( vector2 centerOut,
const vector2 p1,
const vector2 p2,
const vector2 p3 
)

Calculates the circumcenter of a triangle.

Calculates the center of the circle, on which all three points lie. In cases where this is not possible (all three points lie on a line), the method returns false. If the method succeeds, the calculated center is written to centerOut.

References ug::RayRayIntersection2d(), ug::VecDistanceSq(), ug::VecScaleAdd(), and ug::VecSubtract().

Referenced by ug::DelaunayInfo< TAAPos >::classify_face(), ug::MakeDelaunay(), and ug::QualityGridGeneration().

◆ TriangleCircumcenter() [2/2]

UG_API bool ug::TriangleCircumcenter ( vector3 centerOut,
const vector3 p1,
const vector3 p2,
const vector3 p3 
)

Calculates the circumcenter of a triangle.

Calculates the center of the circle, on which all three points lie. In cases where this is not possible (all three points lie on a line), the method returns false. If the method succeeds, the calculated center is written to centerOut.

References ug::ProjectPointToRay(), ug::RayPlaneIntersection(), ug::SMALL, ug::VecDistanceSq(), ug::VecDot(), ug::VecScaleAdd(), and ug::VecSubtract().

◆ TriangleQuality_Area()

template<class vector_t >
number ug::TriangleQuality_Area ( const vector_t &  p1,
const vector_t &  p2,
const vector_t &  p3 
)

returns a value between 0 and 1. The higher the better.

The quality is measured by comparing the triangles area with the sum of the squared length of each side.

a triangle whose sides have all zero length is considered to be a bad triangle - 0 is returned.

References ug::SMALL, ug::TriangleArea(), and ug::VecDistanceSq().

Referenced by ug::ReplaceLowValenceVertices(), and ug::ShapeQualityDegree().

◆ TriangleTriangleIntersection()

bool ug::TriangleTriangleIntersection ( const MathVector< 3 > &  p0,
const MathVector< 3 > &  p1,
const MathVector< 3 > &  p2,
const MathVector< 3 > &  q0,
const MathVector< 3 > &  q1,
const MathVector< 3 > &  q2,
MathVector< 3 > *  ip1Out = NULL,
MathVector< 3 > *  ip2Out = NULL,
number  snapThreshold = SMALL 
)

checks whether two triangles intersect and returns the intervals, if they do.

Uses code by Tomas Moller. See article "A Fast Triangle-Triangle Intersection Test", Journal of Graphics Tools, 2(2), 1997

returns true if the triangles intersect. If ip1Out and ip2Out are specified and if the triangles intersect, ip1Out and ip2Pit will contain the endpoints of the line segment which resembles the intersection. Please specify either both or none.

References tri_tri_intersect().

Referenced by ug::node_tree::Traverser_IntersectFaces::handle_collision_triangles(), and ug::ResolveTriangleIntersections().

◆ urand()

template<class TNumber >
TNumber ug::urand ( TNumber  lowerBound,
TNumber  upperBound 
)