00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef _GMTL_PLANEOPS_H_
00036 #define _GMTL_PLANEOPS_H_
00037
00038 #include <gmtl/Defines.h>
00039 #include <gmtl/Plane.h>
00040 #include <gmtl/Math.h>
00041
00042 namespace gmtl
00043 {
00044
00058 template< class DATA_TYPE >
00059 DATA_TYPE distance( const Plane<DATA_TYPE>& plane, const Point<DATA_TYPE, 3>& pt )
00060 {
00061 return ( dot(plane.mNorm, static_cast< Vec<DATA_TYPE, 3> >(pt)) - plane.mOffset );
00062 }
00063
00074 template< class DATA_TYPE >
00075 PlaneSide whichSide( const Plane<DATA_TYPE>& plane,
00076 const Point<DATA_TYPE, 3>& pt )
00077 {
00078 DATA_TYPE dist = distance( plane, pt );
00079
00080 if ( dist < DATA_TYPE(0) )
00081 return NEG_SIDE;
00082 else if ( dist > DATA_TYPE(0) )
00083 return POS_SIDE;
00084 else
00085 return ON_PLANE;
00086 }
00087
00099 template< class DATA_TYPE >
00100 PlaneSide whichSide( const Plane<DATA_TYPE>& plane,
00101 const Point<DATA_TYPE, 3>& pt,
00102 const DATA_TYPE& eps )
00103 {
00104 DATA_TYPE dist = distance( plane, pt );
00105
00106 if ( dist < eps )
00107 return NEG_SIDE;
00108 else if ( dist > eps )
00109 return POS_SIDE;
00110 else
00111 return ON_PLANE;
00112 }
00113
00124 template< class DATA_TYPE >
00125 DATA_TYPE findNearestPt( const Plane<DATA_TYPE>& plane,
00126 const Point<DATA_TYPE, 3>& pt,
00127 Point<DATA_TYPE, 3>& result )
00128 {
00129
00130
00131 gmtlASSERT( isNormalized(plane.mNorm) );
00132 DATA_TYPE dist_to_plane(0);
00133 dist_to_plane = plane.mOffset + dot( plane.mNorm, static_cast< Vec<DATA_TYPE, 3> >(pt) );
00134 result = pt - (plane.mNorm * dist_to_plane);
00135 return dist_to_plane;
00136 }
00153 template< class DATA_TYPE >
00154 inline bool operator==( const Plane<DATA_TYPE>& p1, const Plane<DATA_TYPE>& p2 )
00155 {
00156 return ( (p1.mNorm == p2.mNorm) && (p1.mOffset == p2.mOffset) );
00157 }
00158
00168 template< class DATA_TYPE >
00169 inline bool operator!=( const Plane<DATA_TYPE>& p1, const Plane<DATA_TYPE>& p2 )
00170 {
00171 return (! (p1 == p2));
00172 }
00173
00185 template< class DATA_TYPE >
00186 inline bool isEqual( const Plane<DATA_TYPE>& p1, const Plane<DATA_TYPE>& p2,
00187 const DATA_TYPE& eps )
00188 {
00189 gmtlASSERT( eps >= 0 );
00190 return ( (isEqual(p1.mNorm, p2.mNorm, eps)) &&
00191 (Math::isEqual(p1.mOffset, p2.mOffset, eps)) );
00192 }
00196 }
00197
00198 #endif
00199