Main Page | Class Hierarchy | Class List | File List | Class Members

TStdPlane.h

00001 // TStdPlane.h: Schnittstelle für die Klasse TStdPlane.
00002 //
00004 
00005 #if !defined(AFX_TSTDPLANE_H__C0188075_B26B_4FA6_9558_CDE64117F13D__INCLUDED_)
00006 #define AFX_TSTDPLANE_H__C0188075_B26B_4FA6_9558_CDE64117F13D__INCLUDED_
00007 
00008 #if _MSC_VER > 1000
00009 #pragma once
00010 #endif // _MSC_VER > 1000
00011 
00012 #include "TKoo3d.h"
00013 #include "TMatrix3D.h"
00014 //#include "TStdLine.h"
00015 
00016 template <class T> class TStdLine  
00017 {
00018 protected:
00019         
00020         TKoo3d<T> point;
00021         TKoo3d<T> direction;
00022 public:
00023         TStdLine(TKoo3d<T>& p, TKoo3d<T>& d)
00024         {
00025                 point=p;
00026                 direction=d;
00027         };
00028         TKoo3d<T> getPoint()
00029         {
00030                 return point;
00031         };
00032         TKoo3d<T> getDir()
00033         {
00034                 return direction;
00035         };
00036 
00037         virtual ~TStdLine()
00038         {
00039         };
00040         TKoo3d<T> getNormDistPoint(TKoo3d<T>& k, double* s=NULL);
00041         
00042 
00043 };
00044 
00045 
00046 template <class T> class TStdPlane  
00047 {
00048 protected:
00049         
00050 
00051         TKoo3d<T> xAxis;
00052         TKoo3d<T> yAxis;
00053         TKoo3d<T> point;
00054         TKoo3d<T> normV;
00055         T planeEqParam;
00056 public:
00057 
00058         TStdPlane(TKoo3d<T>& p=TKoo3d<GLfloat>(0,0,0), TKoo3d<T>& nV=TKoo3d<GLfloat>(0,0,1))
00059         {
00060                 TKoo3d<T> xBuff(10,0,0);
00061                 yAxis=xBuff*nV;
00062                 if (yAxis==TKoo3d<T>(0,0,0))
00063                 {
00064                         xBuff=TKoo3d<T>(10,10,0);
00065                         yAxis=xBuff*nV;
00066                 }
00067                 xAxis=nV*yAxis;
00068 
00069                 point=p;
00070                 normV=nV;
00071                 planeEqParam=(T)-(normV.vMult(point));
00072         };
00073 
00074         TStdPlane(TKoo3d<T>& p1, TKoo3d<T>& p2, TKoo3d<T>& p3)
00075         {
00076                 xAxis=p1-p2;
00077                 yAxis=p3-p2;
00078                 point=p2;
00079                 normV=xAxis*yAxis;
00080                 planeEqParam=(T)-(normV.vMult(point));
00081         };
00082         virtual ~TStdPlane()
00083         {
00084         };
00085         template <class A> A getNormDist(TKoo3d<A>& p)
00086         {
00087 
00088                 return (normV.v[0]*p.v[0]+normV.v[1]*p.v[1]+normV.v[2]*p.v[2]+planeEqParam)*(A)(1.0/normV.betrag());
00089         }
00090         template <class A> TKoo3d<A> intersect(TStdLine<A>& line)
00091         {
00092                 TMatrix3D<T> mBuffEins;
00093                 TMatrix3D<T> mBuff;
00094                 TKoo3d<A> retBuff;
00095                 double det;
00096                 
00097                 int i;
00098                 
00099                 for (i=0;i<3;i++)
00100                 {
00101                         mBuff.v[0][i]=xAxis.v[i];       mBuff.v[1][i]=yAxis.v[i];       mBuff.v[2][i]=-line.getDir().v[i];
00102                 }
00103                 det=mBuff.determinante();
00104                 //x
00105                 for (i=0;i<3;i++)
00106                 {
00107                         mBuffEins.v[0][i]=(A)line.getPoint().v[i]-point.v[i];   mBuffEins.v[1][i]=yAxis.v[i];   mBuffEins.v[2][i]=-line.getDir().v[i];
00108                 }
00109                 retBuff.v[0]=(A)(mBuffEins.determinante()/det);
00110                 //y
00111                 for (i=0;i<3;i++)
00112                 {
00113                         mBuffEins.v[0][i]=(A)xAxis.v[i];        mBuffEins.v[1][i]=line.getPoint().v[i]-point.v[i];      mBuffEins.v[2][i]=-line.getDir().v[i];
00114                 }
00115                 
00116                 retBuff.v[1]=(A)(mBuffEins.determinante()/det);
00117                 //v
00118                 for (i=0;i<3;i++)
00119                 {
00120                         mBuffEins.v[0][i]=(A)xAxis.v[i];        mBuffEins.v[1][i]=yAxis.v[i];   mBuffEins.v[2][i]=line.getPoint().v[i]-point.v[i];
00121                 }
00122                 retBuff.v[2]=(A)(mBuffEins.determinante()/det);
00123                 
00124                 
00125 
00126                 return retBuff;
00127         };
00128         template <class A> TKoo3d<A> getIntersectPoint(TStdLine<A>& line, double* su=NULL)
00129         {
00130                 
00131                 
00132                 double s=(-(planeEqParam+normV.vMult(line.getPoint())))/(normV.vMult(line.getDir()));
00133                 if (su)
00134                         *su=s;
00135                 return line.getPoint()+line.getDir()*(A)s;
00136         };
00137         
00138 
00139 };
00140 
00141 
00142 template <class T> TKoo3d<T> TStdLine<T>::getNormDistPoint(TKoo3d<T>& k, double* s)
00143 {
00144         TStdPlane<T> planeBuff(k,direction);
00145         
00146         return planeBuff.getIntersectPoint(*this,s);
00147 }
00148 
00149 
00150 #endif // !defined(AFX_TSTDPLANE_H__C0188075_B26B_4FA6_9558_CDE64117F13D__INCLUDED_)
00151  

Generated on Wed Dec 3 00:44:09 2003 for Volvis by doxygen 1.3.5