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

/ray/src/lib/numerics/3d/plane3.cc

Go to the documentation of this file.
00001 /*
00002  * lib/numerics/3d/plane3.cc
00003  * 
00004  * Plane template which represents plane in 3 dimensions. 
00005  * 
00006  * Copyright (c) 2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 
00007  * 
00008  * This file may be distributed and/or modified under the terms of the 
00009  * GNU General Public License version 2 as published by the Free Software 
00010  * Foundation. (See COPYING.GPL for details.)
00011  * 
00012  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014  * 
00015  */
00016 
00017 #include "plane3.h"
00018 
00019 namespace NUM   // numerics
00020 {
00021 
00022 // This is a hack which makes sure that the required instances for dbl 
00023 // and flt are emitted. 
00024 void _OMatrixInstantiationDummy()
00025 {
00026     {
00027         Plane3<dbl> *p=NULL;
00028         Vector3<dbl> *v=NULL;
00029         p->compute(*v,*v,*v);
00030     }
00031     {
00032         Plane3<flt> *p=NULL;
00033         Vector3<flt> *v=NULL;
00034         p->compute(*v,*v,*v);
00035     }
00036 }
00037 
00038 
00039 template<typename T>int Plane3<T>::compute(const Vector3<T> &p0,
00040     const Vector3<T> &p1,const Vector3<T> &p2)
00041 {
00042     // Compute the normal vector: 
00043     T da[3] = { p0[0]-p1[0], p0[1]-p1[1], p0[2]-p1[2] };
00044     T db[3] = { p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2] };
00045     
00046     // normal = da x db. 
00047     _normal.cross(da,db);
00048     
00049     // Normalize the normal vector: 
00050     T len=_normal.len();
00051     if(len==0.0)
00052     {  _dist=0;  return(-2);  }  // normal are already 0 since len=0. 
00053     
00054     _normal*=1/len;
00055     
00056     // Compute distance from origin: 
00057     _dist = -dot(_normal,p0);
00058     
00059     return(0);
00060 }
00061 
00062 }  // end of namespace NUM

Generated on Sat Feb 19 22:33:45 2005 for Ray by doxygen 1.3.5