Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

PlaneOps.h

Go to the documentation of this file.
00001 /************************************************************** ggt-head beg
00002  *
00003  * GGT: Generic Graphics Toolkit
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum
00007  *
00008  * -----------------------------------------------------------------
00009  * File:          $RCSfile: PlaneOps.h,v $
00010  * Date modified: $Date: 2003/03/03 00:54:05 $
00011  * Version:       $Revision: 1.11 $
00012  * -----------------------------------------------------------------
00013  *
00014  *********************************************************** ggt-head end */
00015 /*************************************************************** ggt-cpr beg
00016 *
00017 * GGT: The Generic Graphics Toolkit
00018 * Copyright (C) 2001,2002 Allen Bierbaum
00019 *
00020 * This library is free software; you can redistribute it and/or
00021 * modify it under the terms of the GNU Lesser General Public
00022 * License as published by the Free Software Foundation; either
00023 * version 2.1 of the License, or (at your option) any later version.
00024 *
00025 * This library is distributed in the hope that it will be useful,
00026 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00028 * Lesser General Public License for more details.
00029 *
00030 * You should have received a copy of the GNU Lesser General Public
00031 * License along with this library; if not, write to the Free Software
00032 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00033 *
00034  ************************************************************ ggt-cpr end */
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    // GGI:  p297
00130    // GGII: p223
00131    gmtlASSERT( isNormalized(plane.mNorm) );   // Assert: Normalized
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 } // namespace gmtl
00197 
00198 #endif
00199 

Generated on Mon Apr 7 15:28:55 2003 for GenericMathTemplateLibrary by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002