Wm4Query3.inl

Go to the documentation of this file.
00001 // Wild Magic Source Code
00002 // David Eberly
00003 // http://www.geometrictools.com
00004 // Copyright (c) 1998-2007
00005 //
00006 // This library is free software; you can redistribute it and/or modify it
00007 // under the terms of the GNU Lesser General Public License as published by
00008 // the Free Software Foundation; either version 2.1 of the License, or (at
00009 // your option) any later version.  The license is available for reading at
00010 // either of the locations:
00011 //     http://www.gnu.org/copyleft/lgpl.html
00012 //     http://www.geometrictools.com/License/WildMagicLicense.pdf
00013 // The license applies to versions 0 through 4 of Wild Magic.
00014 //
00015 // Version: 4.0.0 (2006/06/28)
00016 
00017 namespace Wm4
00018 {
00019 //----------------------------------------------------------------------------
00020 template <class Real>
00021 Query3<Real>::Query3 (int iVQuantity, const Vector3<Real>* akVertex)
00022 {
00023     assert(iVQuantity > 0 && akVertex);
00024     m_iVQuantity = iVQuantity;
00025     m_akVertex = akVertex;
00026 }
00027 //----------------------------------------------------------------------------
00028 template <class Real>
00029 Query3<Real>::~Query3 ()
00030 {
00031 }
00032 //----------------------------------------------------------------------------
00033 template <class Real>
00034 Query::Type Query3<Real>::GetType () const
00035 {
00036     return Query::QT_REAL;
00037 }
00038 //----------------------------------------------------------------------------
00039 template <class Real>
00040 int Query3<Real>::GetQuantity () const
00041 {
00042     return m_iVQuantity;
00043 }
00044 //----------------------------------------------------------------------------
00045 template <class Real>
00046 const Vector3<Real>* Query3<Real>::GetVertices () const
00047 {
00048     return m_akVertex;
00049 }
00050 //----------------------------------------------------------------------------
00051 template <class Real>
00052 int Query3<Real>::ToPlane (int i, int iV0, int iV1, int iV2) const
00053 {
00054     return ToPlane(m_akVertex[i],iV0,iV1,iV2);
00055 }
00056 //----------------------------------------------------------------------------
00057 template <class Real>
00058 int Query3<Real>::ToPlane (const Vector3<Real>& rkP, int iV0, int iV1,
00059     int iV2) const
00060 {
00061     const Vector3<Real>& rkV0 = m_akVertex[iV0];
00062     const Vector3<Real>& rkV1 = m_akVertex[iV1];
00063     const Vector3<Real>& rkV2 = m_akVertex[iV2];
00064 
00065     Real fX0 = rkP[0] - rkV0[0];
00066     Real fY0 = rkP[1] - rkV0[1];
00067     Real fZ0 = rkP[2] - rkV0[2];
00068     Real fX1 = rkV1[0] - rkV0[0];
00069     Real fY1 = rkV1[1] - rkV0[1];
00070     Real fZ1 = rkV1[2] - rkV0[2];
00071     Real fX2 = rkV2[0] - rkV0[0];
00072     Real fY2 = rkV2[1] - rkV0[1];
00073     Real fZ2 = rkV2[2] - rkV0[2];
00074 
00075     Real fDet3 = Det3(fX0,fY0,fZ0,fX1,fY1,fZ1,fX2,fY2,fZ2);
00076     return (fDet3 > (Real)0.0 ? +1 : (fDet3 < (Real)0.0 ? -1 : 0));
00077 }
00078 //----------------------------------------------------------------------------
00079 template <class Real>
00080 int Query3<Real>::ToTetrahedron (int i, int iV0, int iV1, int iV2,
00081     int iV3) const
00082 {
00083     return ToTetrahedron(m_akVertex[i],iV0,iV1,iV2,iV3);
00084 }
00085 //----------------------------------------------------------------------------
00086 template <class Real>
00087 int Query3<Real>::ToTetrahedron (const Vector3<Real>& rkP, int iV0,
00088     int iV1, int iV2, int iV3) const
00089 {
00090     int iSign0 = ToPlane(rkP,iV1,iV2,iV3);
00091     if (iSign0 > 0)
00092     {
00093         return +1;
00094     }
00095 
00096     int iSign1 = ToPlane(rkP,iV0,iV2,iV3);
00097     if (iSign1 < 0)
00098     {
00099         return +1;
00100     }
00101 
00102     int iSign2 = ToPlane(rkP,iV0,iV1,iV3);
00103     if (iSign2 > 0)
00104     {
00105         return +1;
00106     }
00107 
00108     int iSign3 = ToPlane(rkP,iV0,iV1,iV2);
00109     if (iSign3 < 0)
00110     {
00111         return +1;
00112     }
00113 
00114     return ((iSign0 && iSign1 && iSign2 && iSign3) ? -1 : 0);
00115 }
00116 //----------------------------------------------------------------------------
00117 template <class Real>
00118 int Query3<Real>::ToCircumsphere (int i, int iV0, int iV1, int iV2,
00119     int iV3) const
00120 {
00121     return ToCircumsphere(m_akVertex[i],iV0,iV1,iV2,iV3);
00122 }
00123 //----------------------------------------------------------------------------
00124 template <class Real>
00125 int Query3<Real>::ToCircumsphere (const Vector3<Real>& rkP, int iV0,
00126     int iV1, int iV2, int iV3) const
00127 {
00128     const Vector3<Real>& rkV0 = m_akVertex[iV0];
00129     const Vector3<Real>& rkV1 = m_akVertex[iV1];
00130     const Vector3<Real>& rkV2 = m_akVertex[iV2];
00131     const Vector3<Real>& rkV3 = m_akVertex[iV3];
00132 
00133     Real fS0x = rkV0[0] + rkP[0];
00134     Real fD0x = rkV0[0] - rkP[0];
00135     Real fS0y = rkV0[1] + rkP[1];
00136     Real fD0y = rkV0[1] - rkP[1];
00137     Real fS0z = rkV0[2] + rkP[2];
00138     Real fD0z = rkV0[2] - rkP[2];
00139     Real fS1x = rkV1[0] + rkP[0];
00140     Real fD1x = rkV1[0] - rkP[0];
00141     Real fS1y = rkV1[1] + rkP[1];
00142     Real fD1y = rkV1[1] - rkP[1];
00143     Real fS1z = rkV1[2] + rkP[2];
00144     Real fD1z = rkV1[2] - rkP[2];
00145     Real fS2x = rkV2[0] + rkP[0];
00146     Real fD2x = rkV2[0] - rkP[0];
00147     Real fS2y = rkV2[1] + rkP[1];
00148     Real fD2y = rkV2[1] - rkP[1];
00149     Real fS2z = rkV2[2] + rkP[2];
00150     Real fD2z = rkV2[2] - rkP[2];
00151     Real fS3x = rkV3[0] + rkP[0];
00152     Real fD3x = rkV3[0] - rkP[0];
00153     Real fS3y = rkV3[1] + rkP[1];
00154     Real fD3y = rkV3[1] - rkP[1];
00155     Real fS3z = rkV3[2] + rkP[2];
00156     Real fD3z = rkV3[2] - rkP[2];
00157     Real fW0 = fS0x*fD0x + fS0y*fD0y + fS0z*fD0z;
00158     Real fW1 = fS1x*fD1x + fS1y*fD1y + fS1z*fD1z;
00159     Real fW2 = fS2x*fD2x + fS2y*fD2y + fS2z*fD2z;
00160     Real fW3 = fS3x*fD3x + fS3y*fD3y + fS3z*fD3z;
00161     Real fDet4 = Det4(fD0x,fD0y,fD0z,fW0,fD1x,fD1y,fD1z,fW1,fD2x,
00162         fD2y,fD2z,fW2,fD3x,fD3y,fD3z,fW3);
00163 
00164     return (fDet4 > (Real)0.0 ? 1 : (fDet4 < (Real)0.0 ? -1 : 0));
00165 }
00166 //----------------------------------------------------------------------------
00167 template <class Real>
00168 Real Query3<Real>::Dot (Real fX0, Real fY0, Real fZ0, Real fX1, Real fY1,
00169     Real fZ1)
00170 {
00171     return fX0*fX1 + fY0*fY1 + fZ0*fZ1;
00172 }
00173 //----------------------------------------------------------------------------
00174 template <class Real>
00175 Real Query3<Real>::Det3 (Real fX0, Real fY0, Real fZ0, Real fX1, Real fY1,
00176     Real fZ1, Real fX2, Real fY2, Real fZ2)
00177 {
00178     Real fC00 = fY1*fZ2 - fY2*fZ1;
00179     Real fC01 = fY2*fZ0 - fY0*fZ2;
00180     Real fC02 = fY0*fZ1 - fY1*fZ0;
00181     return fX0*fC00 + fX1*fC01 + fX2*fC02;
00182 }
00183 //----------------------------------------------------------------------------
00184 template <class Real>
00185 Real Query3<Real>::Det4 (Real fX0, Real fY0, Real fZ0, Real fW0, Real fX1,
00186     Real fY1, Real fZ1, Real fW1, Real fX2, Real fY2, Real fZ2, Real fW2,
00187     Real fX3, Real fY3, Real fZ3, Real fW3)
00188 {
00189     Real fA0 = fX0*fY1 - fX1*fY0;
00190     Real fA1 = fX0*fY2 - fX2*fY0;
00191     Real fA2 = fX0*fY3 - fX3*fY0;
00192     Real fA3 = fX1*fY2 - fX2*fY1;
00193     Real fA4 = fX1*fY3 - fX3*fY1;
00194     Real fA5 = fX2*fY3 - fX3*fY2;
00195     Real fB0 = fZ0*fW1 - fZ1*fW0;
00196     Real fB1 = fZ0*fW2 - fZ2*fW0;
00197     Real fB2 = fZ0*fW3 - fZ3*fW0;
00198     Real fB3 = fZ1*fW2 - fZ2*fW1;
00199     Real fB4 = fZ1*fW3 - fZ3*fW1;
00200     Real fB5 = fZ2*fW3 - fZ3*fW2;
00201     return fA0*fB5-fA1*fB4+fA2*fB3+fA3*fB2-fA4*fB1+fA5*fB0;
00202 }
00203 //----------------------------------------------------------------------------
00204 } //namespace Wm4

Generated on Wed Nov 23 19:01:07 2011 for FreeCAD by  doxygen 1.6.1