### Moved Some functions from Math_Tools to ACG Geometry

```Some more documentation and grouping for ACG Geometry

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9329 383ad7c9-94d9-4d36-a494-682f7c89f535```
parent b462fac4
 ... ... @@ -697,6 +697,49 @@ distLineLineSquared( const VectorT& _v00, return fabs(fSqrDist); } //----------------------------------------------------------------------------- template < typename VectorT , typename ValueT > inline ValueT distPlane(const VectorT& _porigin, const VectorT& _pnormal, const VectorT& _point) { assert( fabs(_pnormal.norm()) > 0.0000000001) ; return( ( (_point - _porigin) | _pnormal ) ); } //----------------------------------------------------------------------------- template < typename VectorT > VectorT projectToEdge(const VectorT& _start , const VectorT& _end , const VectorT& _point ) { VectorT direction = ( _end - _start ).normalize(); assert( fabs(direction.norm()) > 0.0000000001) ; const VectorT projected_point = ( ( _point - _start ) | direction ) * direction + _start; if ( ( ( projected_point - _start ) | direction ) > ( ( _end - _start ) | direction ) ) return _end; if ( ( ( projected_point - _start ) | direction ) < 0 ) return _start; return projected_point; } //----------------------------------------------------------------------------- template < typename VectorT > inline VectorT projectToPlane(const VectorT& _porigin, const VectorT& _pnormal, const VectorT& _point) { return (_point - _pnormal * dist_plane< VectorT , double >( _porigin , _pnormal , _point ) ); } //----------------------------------------------------------------------------- ... ...
 ... ... @@ -90,70 +90,6 @@ triangleAreaSquared( const Vec& _v0, const Vec& _v2 ); /// distance from point _p to line (_v0,_v1) template typename Vec::value_type distPointLine( const Vec& _p, const Vec& _v0, const Vec& _v1, Vec* _min_v=0 ) { return sqrt(distPointLineSquared(_p, _v0, _v1, _min_v)); } /// squared distance from point _p to line (_v0,_v1) template typename Vec::value_type distPointLineSquared( const Vec& _p, const Vec& _v0, const Vec& _v1, Vec* _min_v=0); /// distance from point _p to triangle (_v0, _v1, _v2) template typename Vec::value_type distPointTriangle( const Vec& _p, const Vec& _v0, const Vec& _v1, const Vec& _v2, Vec& _nearestPoint ) { return sqrt(distPointTriangleSquared(_p, _v0, _v1, _v2, _nearestPoint)); } /// squared distance from point _p to triangle (_v0, _v1, _v2) template typename Vec::value_type distPointTriangleSquared( const Vec& _p, const Vec& _v0, const Vec& _v1, const Vec& _v2, Vec& _nearestPoint ); /// squared distance of lines (_v00, _v01) and (_v10, _v11) template Scalar distLineLineSquared( const VectorT& _v00, const VectorT& _v01, const VectorT& _v10, const VectorT& _v11, VectorT* _min_v0=0, VectorT* _min_v1=0, bool _fastApprox=false ); /// distance of lines (_v00, _v01) and (_v10, _v11) template Scalar distLineLine( const VectorT& _v00, const VectorT& _v01, const VectorT& _v10, const VectorT& _v11, VectorT* _min_v0=0, VectorT* _min_v1=0 ) { return sqrt(distLineLineSquared(_v00, _v01, _v10, _v11, _min_v0, _min_v1)); } /// construct min. enclosing sphere ... ... @@ -256,39 +192,11 @@ perpendicular( const VectorT& _v ); //== 2D STUFF ================================================================= /// barycentric coord of _p w.r.t. (_u,_v,_w) in 2D template bool baryCoord( const VectorT& _p, const VectorT& _u, const VectorT& _v, const VectorT& _w, VectorT& _result ); /// is point _p in triangle (_v0,_v1,_v2)? template bool isInTriangle( const VectorT& _p, const VectorT& _u, const VectorT& _v, const VectorT& _w ) { VectorT bary; if (baryCoord(_p, _u, _v, _w, bary)) return ((bary>0.0) && (bary>0.0) && (bary>0.0)); else { std::cerr << "point in triangle error\n"; return false; } } //== 2D STUFF ================================================================= /// orientation of point _p w.r.t. line through _v0,_v1 /// orientation of point _p w.r.t. line through _v0,_v1 in 2D template Scalar pointLineOrientation( const VectorT& _p, ... ... @@ -302,7 +210,7 @@ pointLineOrientation( const VectorT& _p, /// are 3 vertices in counterclockwise order? /// are 3 vertices in counterclockwise order? in 2D template bool isCCW( const VectorT& _v0, ... ... @@ -313,7 +221,7 @@ isCCW( const VectorT& _v0, } /// are 3 vertices in clockwise order? /// are 3 vertices in clockwise order? in 2D template bool isCW( const VectorT& _v0, ... ... @@ -335,32 +243,198 @@ lineIntersection( const VectorT& _v0, Scalar& _t2 ); /// return circumcenter of triangle (_v0,_v1,_v2) //=========================================================================== /** @name Distance Functions ( N-Dimensional ) * @{ */ //=========================================================================== /// distance from point _p to line (_v0,_v1) template typename Vec::value_type distPointLine( const Vec& _p, const Vec& _v0, const Vec& _v1, Vec* _min_v=0 ) { return sqrt(distPointLineSquared(_p, _v0, _v1, _min_v)); } /// squared distance from point _p to line (_v0,_v1) template typename Vec::value_type distPointLineSquared( const Vec& _p, const Vec& _v0, const Vec& _v1, Vec* _min_v=0); /// distance from point _p to triangle (_v0, _v1, _v2) template typename Vec::value_type distPointTriangle( const Vec& _p, const Vec& _v0, const Vec& _v1, const Vec& _v2, Vec& _nearestPoint ) { return sqrt(distPointTriangleSquared(_p, _v0, _v1, _v2, _nearestPoint)); } /// squared distance from point _p to triangle (_v0, _v1, _v2) template typename Vec::value_type distPointTriangleSquared( const Vec& _p, const Vec& _v0, const Vec& _v1, const Vec& _v2, Vec& _nearestPoint ); /// squared distance of lines (_v00, _v01) and (_v10, _v11) template Scalar distLineLineSquared( const VectorT& _v00, const VectorT& _v01, const VectorT& _v10, const VectorT& _v11, VectorT* _min_v0=0, VectorT* _min_v1=0, bool _fastApprox=false ); /// distance of lines (_v00, _v01) and (_v10, _v11) template Scalar distLineLine( const VectorT& _v00, const VectorT& _v01, const VectorT& _v10, const VectorT& _v11, VectorT* _min_v0=0, VectorT* _min_v1=0 ) { return sqrt(distLineLineSquared(_v00, _v01, _v10, _v11, _min_v0, _min_v1)); } /** \brief Checks the distance from a point to a plane * * * @param _porigin Planes origin * @param _pnormal Plane normal ( has to be normalized!) * @param _point point to test * @return distance */ template < typename VectorT , typename ValueT > inline ValueT distPlane(const VectorT& _porigin, const VectorT& _pnormal, const VectorT& _point); /** @} */ //=========================================================================== /** @name Projection Functions ( N-Dimensional ) * @{ */ //=========================================================================== /** project one point to an edge. If its projection is not on the edge itself, the start or the endpoint is returned @param _start beginning of edge @param _end end of the edge @param _point point to be projected */ template < typename VectorT > VectorT projectToEdge(const VectorT& _start , const VectorT& _end , const VectorT& _point ); /** \brief projects a point to a plane * @param _porigin Planes origin * @param _pnormal Plane normal ( has to be normalized! ) * @param _point point to project * @return projected point */ template < typename VectorT > inline VectorT projectToPlane(const VectorT& _porigin, const VectorT& _pnormal, const VectorT& _point); /** @} */ //=========================================================================== /** @name Triangle Functions (2D Only!!) * @{ */ //=========================================================================== /** \brief return circumcenter of triangle (_v0,_v1,_v2) * */ /// barycentric coord of _p w.r.t. (_u,_v,_w) in 2D template bool baryCoord( const VectorT& _p, const VectorT& _u, const VectorT& _v, const VectorT& _w, VectorT& _result ); /// is point _p in triangle (_v0,_v1,_v2) in 2D template bool isInTriangle( const VectorT& _p, const VectorT& _u, const VectorT& _v, const VectorT& _w ) { VectorT bary; if (baryCoord(_p, _u, _v, _w, bary)) return ((bary>0.0) && (bary>0.0) && (bary>0.0)); else { std::cerr << "point in triangle error\n"; return false; } } template bool circumCenter( const VectorT& _v0, const VectorT& _v1, const VectorT& _v2, VectorT& _result ); const VectorT& _v1, const VectorT& _v2, VectorT& _result ); /** @} */ //== N-DIM STUFF ============================================================== //=========================================================================== /** @name Triangle Functions N-Dimensional * @{ */ //=========================================================================== /// return aspect ratio of triangle /** \brief return aspect ratio of triangle * */ template Scalar aspectRatio( const VectorT& _v0, const VectorT& _v1, const VectorT& _v2 ); const VectorT& _v1, const VectorT& _v2 ); /// return roundness of triangle: 1=equilateral, 0=colinear /** \brief return roundness of triangle: 1=equilateral, 0=colinear * */ template Scalar roundness( const VectorT& _v0, const VectorT& _v1, const VectorT& _v2 ); const VectorT& _v1, const VectorT& _v2 ); /** @} */ //============================================================================= } // namespace Geometry ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment