Developer Documentation
ACG::Geometry Namespace Reference

Classes

class  PlaneT
 
class  QuadricT
 

Typedefs

typedef PlaneT< float > Planef
 
typedef PlaneT< double > Planed
 
typedef QuadricT< float > Quadricf
 Quadric using floats.
 
typedef QuadricT< double > Quadricd
 Quadric using double.
 

Functions

template<typename Scalar >
bool edgeConvexPolygonIntersection (std::vector< VectorT< Scalar, 3 > > _polygon_points, VectorT< Scalar, 3 > _v0, VectorT< Scalar, 3 > _v1, VectorT< Scalar, 3 > &_result)
 Get intersection point of a ray and a convex polygon. More...
 
template<class Vec >
Vec::value_type distPointTriangleSquared (const Vec &_p, const Vec &_v0, const Vec &_v1, const Vec &_v2, Vec &_nearestPoint, bool _stable)
 
template<typename Scalar >
bool rotationOfTwoVectors (const VectorT< Scalar, 3 > &_v0, const VectorT< Scalar, 3 > &_v1, VectorT< Scalar, 3 > &_axis, Scalar &_angle, bool _degree=true)
 Get rotation axis and signed angle of rotation between two vectors. More...
 
template<typename Scalar >
bool circumCenter (const VectorT< Scalar, 3 > &_v0, const VectorT< Scalar, 3 > &_v1, const VectorT< Scalar, 3 > &_v2, const VectorT< Scalar, 3 > &_v3, VectorT< Scalar, 3 > &_result)
 return circumcenter of tetrahedron (_v0,_v1,_v2,_v3)
 
template<typename Scalar >
VectorT< Scalar, 3 > perpendicular (const VectorT< Scalar, 3 > &_v)
 find a vector that's perpendicular to _v More...
 
template<typename Scalar >
bool lineIntersection (const VectorT< Scalar, 2 > &_v0, const VectorT< Scalar, 2 > &_v1, const VectorT< Scalar, 2 > &_v2, const VectorT< Scalar, 2 > &_v3, Scalar &_t1, Scalar &_t2)
 intersect two line segments (_v0,_v1) and (_v2,_v3)
 
template<typename Vec >
bool triangleIntersection (const Vec &_o, const Vec &_dir, const Vec &_v0, const Vec &_v1, const Vec &_v2, typename Vec::value_type &_t, typename Vec::value_type &_u, typename Vec::value_type &_v)
 Intersect a ray and a triangle. More...
 
template<typename Vec >
bool axisAlignedBBIntersection (const Vec &_o, const Vec &_dir, const Vec &_bbmin, const Vec &_bbmax, typename Vec::value_type &_t0, typename Vec::value_type &_t1)
 Intersect a ray and an axis aligned bounding box. More...
 
template<typename Scalar >
Scalar circumRadiusSquared (const VectorT< Scalar, 3 > &_v0, const VectorT< Scalar, 3 > &_v1, const VectorT< Scalar, 3 > &_v2, const VectorT< Scalar, 3 > &_v3)
 return squared radius of circumcircle of tetrahedron (_v0,_v1,_v2,_v3)
 
template<typename Scalar >
Scalar circumRadius (const VectorT< Scalar, 3 > &_v0, const VectorT< Scalar, 3 > &_v1, const VectorT< Scalar, 3 > &_v2, const VectorT< Scalar, 3 > &_v3)
 return radius of circumcircle of tetrahedron (_v0,_v1,_v2,_v3)
 
template<typename Scalar >
Scalar pointLineOrientation (const VectorT< Scalar, 2 > &_p, const VectorT< Scalar, 2 > &_v0, const VectorT< Scalar, 2 > &_v1)
 orientation of point _p w.r.t. line through _v0,_v1 in 2D
 
template<typename Scalar >
bool isCCW (const VectorT< Scalar, 2 > &_v0, const VectorT< Scalar, 2 > &_v1, const VectorT< Scalar, 2 > &_v2)
 are 3 vertices in counterclockwise order? in 2D
 
template<typename Scalar >
bool isCW (const VectorT< Scalar, 2 > &_v0, const VectorT< Scalar, 2 > &_v1, const VectorT< Scalar, 2 > &_v2)
 are 3 vertices in clockwise order? in 2D
 
bool isNan (double x)
 Return false if x is not a number.
 
template<typename VectorT , typename ValueT >
ValueT getFullangle (VectorT _vector1, VectorT _vector2, const VectorT &_normal, bool &_skip)
 
template<typename ValueT >
ValueT angleDist (const ValueT &angle0, const ValueT &angle1)
 
template<typename ValueT >
ValueT getAngle (const ValueT &_cos, const ValueT &_sin)
 
template<typename ValueT >
ValueT radToDeg (const ValueT &_angle)
 
template<typename ValueT >
ValueT degToRad (const ValueT &_angle)
 
Triangle Functions 3-Dimensional
template<typename Scalar >
bool baryCoord (const VectorT< Scalar, 3 > &_p, const VectorT< Scalar, 3 > &_u, const VectorT< Scalar, 3 > &_v, const VectorT< Scalar, 3 > &_w, VectorT< Scalar, 3 > &_result)
 
template<typename Scalar >
bool circumCenter (const VectorT< Scalar, 3 > &_v0, const VectorT< Scalar, 3 > &_v1, const VectorT< Scalar, 3 > &_v2, VectorT< Scalar, 3 > &_result)
 return circumcenter of triangle (_v0,_v1,_v2)
 
template<typename Scalar >
Scalar circumRadiusSquared (const VectorT< Scalar, 3 > &_v0, const VectorT< Scalar, 3 > &_v1, const VectorT< Scalar, 3 > &_v2)
 return squared radius of circumcircle of triangle (_v0,_v1,_v2)
 
template<class VectorT >
int isObtuse (const VectorT &_p0, const VectorT &_p1, const VectorT &_p2)
 
template<typename Scalar >
bool minSphere (const VectorT< Scalar, 3 > &_v0, const VectorT< Scalar, 3 > &_v1, const VectorT< Scalar, 3 > &_v2, VectorT< Scalar, 3 > &_center, Scalar &_radius)
 construct min. enclosing sphere
 
template<typename Scalar >
Scalar minRadiusSquared (const VectorT< Scalar, 3 > &_v0, const VectorT< Scalar, 3 > &_v1, const VectorT< Scalar, 3 > &_v2)
 return squared radius of min. enclosing circle of triangle (_v0,_v1,_v2)
 
template<typename Scalar >
Scalar minRadius (const VectorT< Scalar, 3 > &_v0, const VectorT< Scalar, 3 > &_v1, const VectorT< Scalar, 3 > &_v2)
 return radius of min. enclosing circle of triangle (_v0,_v1,_v2)
 
template<typename Scalar >
Scalar circumRadius (const VectorT< Scalar, 3 > &_v0, const VectorT< Scalar, 3 > &_v1, const VectorT< Scalar, 3 > &_v2)
 return radius of circumcircle of triangle (_v0,_v1,_v2)
 
Triangle Functions N-Dimensional
template<class Vec >
Vec::value_type triangleAreaSquared (const Vec &_v0, const Vec &_v1, const Vec &_v2)
 return squared area of triangle (_v0, _v1, _v2) More...
 
template<typename Scalar , int N>
Scalar aspectRatio (const VectorT< Scalar, N > &_v0, const VectorT< Scalar, N > &_v1, const VectorT< Scalar, N > &_v2)
 return aspect ratio (length/height) of triangle More...
 
template<typename Scalar , int N>
Scalar roundness (const VectorT< Scalar, N > &_v0, const VectorT< Scalar, N > &_v1, const VectorT< Scalar, N > &_v2)
 return roundness of triangle: 1=equilateral, 0=colinear More...
 
template<class Vec >
Vec::value_type triangleArea (const Vec &_v0, const Vec &_v1, const Vec &_v2)
 return area of triangle (_v0, _v1, _v2) More...
 
Distance Functions ( N-Dimensional )
template<class Vec >
Vec::value_type distPointLineSquared (const Vec &_p, const Vec &_v0, const Vec &_v1, Vec *_min_v=0)
 squared distance from point _p to line segment (_v0,_v1) More...
 
template<class Vec >
Vec::value_type distPointTriangleSquared (const Vec &_p, const Vec &_v0, const Vec &_v1, const Vec &_v2, Vec &_nearestPoint)
 squared distance from point _p to triangle (_v0, _v1, _v2)
 
template<class Vec >
Vec::value_type distPointTriangleSquaredStable (const Vec &_p, const Vec &_v0, const Vec &_v1, const Vec &_v2, Vec &_nearestPoint)
 squared distance from point _p to triangle (_v0, _v1, _v2) More...
 
template<typename VectorT , typename ValueT >
ValueT distPointPlane (const VectorT &_porigin, const VectorT &_pnormal, const VectorT &_point)
 Checks the distance from a point to a plane. More...
 
template<class Vec >
Vec::value_type distPointLine (const Vec &_p, const Vec &_v0, const Vec &_v1, Vec *_min_v=0)
 Compute distance from point to line segment. More...
 
template<class Vec >
Vec::value_type distPointTriangle (const Vec &_p, const Vec &_v0, const Vec &_v1, const Vec &_v2, Vec &_nearestPoint)
 distance from point _p to triangle (_v0, _v1, _v2)
 
template<class Vec >
Vec::value_type distPointTriangleStable (const Vec &_p, const Vec &_v0, const Vec &_v1, const Vec &_v2, Vec &_nearestPoint)
 distance from point _p to triangle (_v0, _v1, _v2) More...
 
Distance Functions ( 3-Dimensional )
template<typename Scalar >
Scalar distLineLineSquared (const VectorT< Scalar, 3 > &_v00, const VectorT< Scalar, 3 > &_v01, const VectorT< Scalar, 3 > &_v10, const VectorT< Scalar, 3 > &_v11, VectorT< Scalar, 3 > *_min_v0=0, VectorT< Scalar, 3 > *_min_v1=0, bool _fastApprox=false)
 squared distance of lines (_v00, _v01) and (_v10, _v11)
 
template<typename Scalar >
Scalar distLineLine (const VectorT< Scalar, 3 > &_v00, const VectorT< Scalar, 3 > &_v01, const VectorT< Scalar, 3 > &_v10, const VectorT< Scalar, 3 > &_v11, VectorT< Scalar, 3 > *_min_v0=0, VectorT< Scalar, 3 > *_min_v1=0)
 distance of lines (_v00, _v01) and (_v10, _v11)
 
Projection Functions ( N-Dimensional )
template<typename VectorT >
VectorT projectToEdge (const VectorT &_start, const VectorT &_end, const VectorT &_point)
 
template<typename VectorT >
VectorT projectToPlane (const VectorT &_porigin, const VectorT &_pnormal, const VectorT &_point)
 projects a point to a plane More...
 
Triangle Functions (2D Only!!)
template<typename Scalar >
bool baryCoord (const VectorT< Scalar, 2 > &_p, const VectorT< Scalar, 2 > &_u, const VectorT< Scalar, 2 > &_v, const VectorT< Scalar, 2 > &_w, VectorT< Scalar, 3 > &_result)
 return circumcenter of triangle (_v0,_v1,_v2) More...
 
template<typename Scalar >
bool circumCenter (const VectorT< Scalar, 2 > &_v0, const VectorT< Scalar, 2 > &_v1, const VectorT< Scalar, 2 > &_v2, VectorT< Scalar, 2 > &_result)
 return circumcenter of triangle (_v0,_v1,_v2) More...
 
template<typename Scalar >
bool isInTriangle (const VectorT< Scalar, 2 > &_p, const VectorT< Scalar, 2 > &_u, const VectorT< Scalar, 2 > &_v, const VectorT< Scalar, 2 > &_w)
 is point _p in triangle (_v0,_v1,_v2) in 2D
 

Detailed Description

This namespace holds some geometric types as well as geometry algorithms.

Function Documentation

template<typename ValueT >
ValueT ACG::Geometry::angleDist ( const ValueT &  angle0,
const ValueT &  angle1 
)
inline

Calculate the difference between two angles ( minimum distance )

Parameters
angle0angle1
angle1angle2
Returns
The difference between the angles (0..PI)

Definition at line 123 of file AlgorithmsAngleT.cc.

template<typename Scalar , int N>
Scalar ACG::Geometry::aspectRatio ( const VectorT< Scalar, N > &  _v0,
const VectorT< Scalar, N > &  _v1,
const VectorT< Scalar, N > &  _v2 
)

return aspect ratio (length/height) of triangle

Parameters
_v0First point of triangle
_v1Second point of triangle
_v2Third point of triangl

Definition at line 1266 of file Algorithms.cc.

template<typename Vec >
bool ACG::Geometry::axisAlignedBBIntersection ( const Vec &  _o,
const Vec &  _dir,
const Vec &  _bbmin,
const Vec &  _bbmax,
typename Vec::value_type &  _t0,
typename Vec::value_type &  _t1 
)

Intersect a ray and an axis aligned bounding box.

Computes the intersection point between a ray and an axis aligned bounding box

Parameters
_oOrigin of the ray
_dirdirection vector of the ray
_bbminlower left front corner of the bounding box
_bbmaxupper right back corner of the bounding box
_t0if there was an intersection, this value marks the entry point
_t1if there was an intersection, this value marks the exit point
Returns
true if an intersection was found

Definition at line 1367 of file Algorithms.cc.

template<typename Scalar >
bool ACG::Geometry::baryCoord ( const VectorT< Scalar, 3 > &  _p,
const VectorT< Scalar, 3 > &  _u,
const VectorT< Scalar, 3 > &  _v,
const VectorT< Scalar, 3 > &  _w,
VectorT< Scalar, 3 > &  _result 
)

barycentric coord of _p w.r.t. (_u,_v,_w) in 3D _p has to lie in plane (_u,_v,_w)

Definition at line 93 of file Algorithms.cc.

template<typename Scalar >
bool ACG::Geometry::baryCoord ( const VectorT< Scalar, 2 > &  _p,
const VectorT< Scalar, 2 > &  _u,
const VectorT< Scalar, 2 > &  _v,
const VectorT< Scalar, 2 > &  _w,
VectorT< Scalar, 3 > &  _result 
)

return circumcenter of triangle (_v0,_v1,_v2)

barycentric coord of _p w.r.t. (_u,_v,_w) in 2D

Definition at line 1183 of file Algorithms.cc.

template<typename Scalar >
bool ACG::Geometry::circumCenter ( const VectorT< Scalar, 2 > &  _v0,
const VectorT< Scalar, 2 > &  _v1,
const VectorT< Scalar, 2 > &  _v2,
VectorT< Scalar, 2 > &  _result 
)

return circumcenter of triangle (_v0,_v1,_v2)

barycentric coord of _p w.r.t. (_u,_v,_w) in 2D

Definition at line 1236 of file Algorithms.cc.

template<typename ValueT >
ValueT ACG::Geometry::degToRad ( const ValueT &  _angle)
inline

Convert angle from degree to radians

Parameters
_anglein degree
Returns
angle in radians

Definition at line 162 of file AlgorithmsAngleT.cc.

template<class Vec >
Vec::value_type ACG::Geometry::distPointLine ( const Vec &  _p,
const Vec &  _v0,
const Vec &  _v1,
Vec *  _min_v = 0 
)

Compute distance from point to line segment.

Compute the distance from a point p to a line segment and possibly return closest point on segment

Parameters
_pPoint to test
_v0Start of line segment
_v1End of line segment
_min_vPointer to vector, to get the closest point or 0 if it's not required
Returns
Distance to line segment

Definition at line 295 of file Algorithms.hh.

template<class Vec >
Vec::value_type ACG::Geometry::distPointLineSquared ( const Vec &  _p,
const Vec &  _v0,
const Vec &  _v1,
Vec *  _min_v = 0 
)

squared distance from point _p to line segment (_v0,_v1)

Parameters
_pPoint to test
_v0Start of line segment
_v1End of line segment
_min_vPointer to vector, to get the closest point or 0 if it's not required
Returns
Distance to line segment

Definition at line 300 of file Algorithms.cc.

template<typename VectorT , typename ValueT >
ValueT ACG::Geometry::distPointPlane ( const VectorT _porigin,
const VectorT _pnormal,
const VectorT _point 
)
inline

Checks the distance from a point to a plane.

Parameters
_poriginPlanes origin
_pnormalPlane normal ( has to be normalized!)
_pointpoint to test
Returns
distance

Definition at line 872 of file Algorithms.cc.

template<class Vec >
Vec::value_type ACG::Geometry::distPointTriangleSquaredStable ( const Vec &  _p,
const Vec &  _v0,
const Vec &  _v1,
const Vec &  _v2,
Vec &  _nearestPoint 
)

squared distance from point _p to triangle (_v0, _v1, _v2)

In the stable version the distance to the longest edge is returned if the triangle is degenerate.

Parameters
_ppoint to test against triangle
_v0First point of triangle
_v1Second point of triangle
_v2Third point of triangle
Returns
Computed distance

Definition at line 476 of file Algorithms.cc.

template<class Vec >
Vec::value_type ACG::Geometry::distPointTriangleStable ( const Vec &  _p,
const Vec &  _v0,
const Vec &  _v1,
const Vec &  _v2,
Vec &  _nearestPoint 
)

distance from point _p to triangle (_v0, _v1, _v2)

In the stable version the distance to the longest edge is returned if the triangle is degenerate.

Parameters
_v0First point of triangle
_v1Second point of triangle
_v2Third point of triangle
Returns
Computed distance

Definition at line 352 of file Algorithms.hh.

template<typename Scalar >
bool ACG::Geometry::edgeConvexPolygonIntersection ( std::vector< VectorT< Scalar, 3 > >  _polygon_points,
VectorT< Scalar, 3 >  _v0,
VectorT< Scalar, 3 >  _v1,
VectorT< Scalar, 3 > &  _result 
)

Get intersection point of a ray and a convex polygon.

Gets two vertices, _v0 and _v1, and a convex polygon defined by its vertices stored in _polygon_points Computes the intersection point of the ray defined by _v0 and _v1 and stores it to _result Returns true if the intersection point lies inside the polygon

Parameters
_v0The first vertex of a ray
_v1The second vertex if a ray
_polygon_pointsvector of the points bounding the polygon
_resultcontains the intersection point after the computation

Definition at line 182 of file Algorithms.cc.

template<typename ValueT >
ValueT ACG::Geometry::getAngle ( const ValueT &  _cos,
const ValueT &  _sin 
)
inline

Calculate the correct 2D angle if cos and sin of the angle are given This function calculates based on the signs of the acos and asin of the given angles, in which quadrant the angle is and returns the full angle in radians

Parameters
_coscos of angle
_sinsin of angle
Returns
angle

Definition at line 131 of file AlgorithmsAngleT.cc.

template<typename VectorT , typename ValueT >
ValueT ACG::Geometry::getFullangle ( VectorT  _vector1,
VectorT  _vector2,
const VectorT _normal,
bool &  _skip 
)

Return a fully parametrized angle

Parameters
_vector1vector pointing away from center, angle = 0
_vector2vector for which the angle should be calculated
_normalthe normal used to compute if vector2 is left or right of vecor1
_skipFlag to catch nan. If true nan occurred and value should not be used
Returns
the angle (0 .. 2 * PI)

Definition at line 86 of file AlgorithmsAngleT.cc.

template<class VectorT >
int ACG::Geometry::isObtuse ( const VectorT _p0,
const VectorT _p1,
const VectorT _p2 
)

test angles in triangle return 0 if all smaller than 90? return 1 if angle at _p0 ist greater than 90? return 2 if angle at _p1 ist greater than 90? return 3 if angle at _p2 ist greater than 90?

Definition at line 1013 of file Algorithms.cc.

template<typename Scalar >
VectorT< Scalar, 3 > ACG::Geometry::perpendicular ( const VectorT< Scalar, 3 > &  _v)

find a vector that's perpendicular to _v

This function takes a vector and generates a new arbitrary vector that is perpendicular to the input vector.

Parameters
_vInput vector
Returns
Perpendicular vector

Definition at line 1162 of file Algorithms.cc.

template<typename VectorT >
VectorT ACG::Geometry::projectToEdge ( const VectorT _start,
const VectorT _end,
const VectorT _point 
)

project one point to an edge. If its projection is not on the edge itself, the start or the endpoint is returned

Parameters
_startbeginning of edge
_endend of the edge
_pointpoint to be projected

Definition at line 884 of file Algorithms.cc.

template<typename VectorT >
VectorT ACG::Geometry::projectToPlane ( const VectorT _porigin,
const VectorT _pnormal,
const VectorT _point 
)
inline

projects a point to a plane

Parameters
_poriginPlanes origin
_pnormalPlane normal ( has to be normalized! )
_pointpoint to project
Returns
projected point

Definition at line 904 of file Algorithms.cc.

template<typename ValueT >
ValueT ACG::Geometry::radToDeg ( const ValueT &  _angle)
inline

Convert angle from radians to degree

Parameters
_anglein radians
Returns
angle in degree

Definition at line 155 of file AlgorithmsAngleT.cc.

template<typename Scalar >
bool ACG::Geometry::rotationOfTwoVectors ( const VectorT< Scalar, 3 > &  _v0,
const VectorT< Scalar, 3 > &  _v1,
VectorT< Scalar, 3 > &  _axis,
Scalar &  _angle,
bool  _degree = true 
)

Get rotation axis and signed angle of rotation between two vectors.

Get two vectors, _v0 and _v1, and compute rotation axis _v0 % _v1 as well the angle between _v0 and _v1. Note that the angle is always negative. We consider the rotation to be performed from _v0 to _v1. The angle is given in degree if not explicitly demanded in radiant (pass false as fifth parameter).

Parameters
_v0The first vector
_v1The second vector
_axisA reference to a vector in which the rotation axis is stored
_angleA reference to a scalar type in which the signed angle is stored ( in degree)
_degreeIndicates whether the angle should be given in degree or radiant

Definition at line 973 of file Algorithms.cc.

template<typename Scalar , int N>
Scalar ACG::Geometry::roundness ( const VectorT< Scalar, N > &  _v0,
const VectorT< Scalar, N > &  _v1,
const VectorT< Scalar, N > &  _v2 
)

return roundness of triangle: 1=equilateral, 0=colinear

Parameters
_v0First point of triangle
_v1Second point of triangle
_v2Third point of triangl

Definition at line 1302 of file Algorithms.cc.

template<class Vec >
Vec::value_type ACG::Geometry::triangleArea ( const Vec &  _v0,
const Vec &  _v1,
const Vec &  _v2 
)

return area of triangle (_v0, _v1, _v2)

Parameters
_v0First point of triangle
_v1Second point of triangle
_v2Third point of triangl

Definition at line 602 of file Algorithms.hh.

template<class Vec >
Vec::value_type ACG::Geometry::triangleAreaSquared ( const Vec &  _v0,
const Vec &  _v1,
const Vec &  _v2 
)

return squared area of triangle (_v0, _v1, _v2)

Parameters
_v0First point of triangle
_v1Second point of triangle
_v2Third point of triangl

Definition at line 173 of file Algorithms.cc.

template<typename Vec >
bool ACG::Geometry::triangleIntersection ( const Vec &  _o,
const Vec &  _dir,
const Vec &  _v0,
const Vec &  _v1,
const Vec &  _v2,
typename Vec::value_type &  _t,
typename Vec::value_type &  _u,
typename Vec::value_type &  _v 
)

Intersect a ray and a triangle.

Computes the intersection point between a ray and a triangle. The orientation of the triangle does not matter. The distance returned in t will be negative if the triangle is not in the direction given but in the opposite direction.

Parameters
_oorigin of the ray
_dirdirection vector of the ray
_v0first point of the triangle
_v1second point of the triangle
_v2third point of the triangle
_treturned distance from the origin to the intersection, in units of _dir ( negative if before origin!)
_ureturned first barycentric coordinate of the intersection point in the triangle
_vreturned second barycentric coordinate of the intersection point in the triangle
Returns
true if an intersection was found

Definition at line 1317 of file Algorithms.cc.