Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

gfx/Plane

Go to the documentation of this file.
00001 /****************************************************************************
00002   Copyright (C)1996 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details. (http://www.gnu.org)
00013   
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017   
00018   $Id: Plane 1030 2004-02-11 20:46:17Z jungd $
00019   $Revision: 1.3 $
00020   $Date: 2004-02-11 15:46:17 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #ifndef _GFX_PLANE_
00026 #define _GFX_PLANE_
00027 
00028 #include <gfx/gfx>
00029 #include <base/Point3>
00030 #include <base/Vector3>
00031 #include <gfx/Triangle3>
00032 
00033 #include <iostream>
00034 
00035 
00036 namespace gfx {
00037 
00038 // Plane in 3D with Hession normal form: normal . x = -p
00039 class Plane
00040 {
00041 
00042 public:
00043   Plane() {}
00044   
00045   Plane(const Vector3& normal, Real p)
00046     : normal(normal), p(p) { this->normal.normalize(); }
00047   
00048   Plane(Real a, Real b, Real c, Real d)
00049    : normal(a,b,c)
00050   { p = d/normal.length(); normal.normalize();  }
00051      
00052   Plane(const Point3& p1, const Point3& p2, const Point3& p3)
00053   {
00054     normal = cross(p1-p2,p3-p2); normal.normalize();
00055     p = -dot(normal,p1);
00056   }
00057   
00058   Plane(const Triangle3& t)
00059   {
00060     normal = cross(t.p1()-t.p2(),t.p3()-t.p2()); normal.normalize(); 
00061     p = -dot(normal,t.p1()); 
00062   }
00063   
00064   virtual ~Plane() {}
00065         
00066   Real distanceTo(const Point3& pt) const
00067   { return Math::abs(dot(normal,pt) + p); }
00068   
00069   bool contains(const Point3& p) const 
00070   { return Math::equals(distanceTo(p),0); }
00071         
00072   Real classify(const Vector3& v) const
00073   { return dot(normal,v) + p; }
00074 
00075   Vector3 normal;
00076   Real    p;
00077 };
00078 
00079 
00080 // Operations
00081 
00082 inline std::ostream& operator<<(std::ostream& out, const Plane& p) // Output
00083 { return out << "(" << p.normal << "," << p.p << ")"; }
00084 
00085 
00086 } // gfx
00087 
00088 #endif

Generated on Thu Jul 29 15:56:19 2004 for OpenSim by doxygen 1.3.6