Wm4Query2.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 Query2<Real>::Query2 (int iVQuantity, const Vector2<Real>* akVertex)
00022 {
00023     assert(iVQuantity > 0 && akVertex);
00024     m_iVQuantity = iVQuantity;
00025     m_akVertex = akVertex;
00026 }
00027 //----------------------------------------------------------------------------
00028 template <class Real>
00029 Query2<Real>::~Query2 ()
00030 {
00031 }
00032 //----------------------------------------------------------------------------
00033 template <class Real>
00034 Query::Type Query2<Real>::GetType () const
00035 {
00036     return Query::QT_REAL;
00037 }
00038 //----------------------------------------------------------------------------
00039 template <class Real>
00040 int Query2<Real>::GetQuantity () const
00041 {
00042     return m_iVQuantity;
00043 }
00044 //----------------------------------------------------------------------------
00045 template <class Real>
00046 const Vector2<Real>* Query2<Real>::GetVertices () const
00047 {
00048     return m_akVertex;
00049 }
00050 //----------------------------------------------------------------------------
00051 template <class Real>
00052 int Query2<Real>::ToLine (int i, int iV0, int iV1) const
00053 {
00054     return ToLine(m_akVertex[i],iV0,iV1);
00055 }
00056 //----------------------------------------------------------------------------
00057 template <class Real>
00058 int Query2<Real>::ToLine (const Vector2<Real>& rkP, int iV0, int iV1) const
00059 {
00060     const Vector2<Real>& rkV0 = m_akVertex[iV0];
00061     const Vector2<Real>& rkV1 = m_akVertex[iV1];
00062 
00063     Real fX0 = rkP[0] - rkV0[0];
00064     Real fY0 = rkP[1] - rkV0[1];
00065     Real fX1 = rkV1[0] - rkV0[0];
00066     Real fY1 = rkV1[1] - rkV0[1];
00067 
00068     Real fDet2 = Det2(fX0,fY0,fX1,fY1);
00069     return (fDet2 > (Real)0.0 ? +1 : (fDet2 < (Real)0.0 ? -1 : 0));
00070 }
00071 //----------------------------------------------------------------------------
00072 template <class Real>
00073 int Query2<Real>::ToTriangle (int i, int iV0, int iV1, int iV2) const
00074 {
00075     return ToTriangle(m_akVertex[i],iV0,iV1,iV2);
00076 }
00077 //----------------------------------------------------------------------------
00078 template <class Real>
00079 int Query2<Real>::ToTriangle (const Vector2<Real>& rkP, int iV0, int iV1,
00080     int iV2) const
00081 {
00082     int iSign0 = ToLine(rkP,iV1,iV2);
00083     if (iSign0 > 0)
00084     {
00085         return +1;
00086     }
00087 
00088     int iSign1 = ToLine(rkP,iV0,iV2);
00089     if (iSign1 < 0)
00090     {
00091         return +1;
00092     }
00093 
00094     int iSign2 = ToLine(rkP,iV0,iV1);
00095     if (iSign2 > 0)
00096     {
00097         return +1;
00098     }
00099 
00100     return ((iSign0 && iSign1 && iSign2) ? -1 : 0);
00101 }
00102 //----------------------------------------------------------------------------
00103 template <class Real>
00104 int Query2<Real>::ToCircumcircle (int i, int iV0, int iV1, int iV2) const
00105 {
00106     return ToCircumcircle(m_akVertex[i],iV0,iV1,iV2);
00107 }
00108 //----------------------------------------------------------------------------
00109 template <class Real>
00110 int Query2<Real>::ToCircumcircle (const Vector2<Real>& rkP, int iV0,
00111     int iV1, int iV2) const
00112 {
00113     const Vector2<Real>& rkV0 = m_akVertex[iV0];
00114     const Vector2<Real>& rkV1 = m_akVertex[iV1];
00115     const Vector2<Real>& rkV2 = m_akVertex[iV2];
00116 
00117     Real fS0x = rkV0[0] + rkP[0];
00118     Real fD0x = rkV0[0] - rkP[0];
00119     Real fS0y = rkV0[1] + rkP[1];
00120     Real fD0y = rkV0[1] - rkP[1];
00121     Real fS1x = rkV1[0] + rkP[0];
00122     Real fD1x = rkV1[0] - rkP[0];
00123     Real fS1y = rkV1[1] + rkP[1];
00124     Real fD1y = rkV1[1] - rkP[1];
00125     Real fS2x = rkV2[0] + rkP[0];
00126     Real fD2x = rkV2[0] - rkP[0];
00127     Real fS2y = rkV2[1] + rkP[1];
00128     Real fD2y = rkV2[1] - rkP[1];
00129     Real fZ0 = fS0x*fD0x + fS0y*fD0y;
00130     Real fZ1 = fS1x*fD1x + fS1y*fD1y;
00131     Real fZ2 = fS2x*fD2x + fS2y*fD2y;
00132     Real fDet3 = Det3(fD0x,fD0y,fZ0,fD1x,fD1y,fZ1,fD2x,fD2y,fZ2);
00133     return (fDet3 < (Real)0.0 ? 1 : (fDet3 > (Real)0.0 ? -1 : 0));
00134 }
00135 //----------------------------------------------------------------------------
00136 template <class Real>
00137 Real Query2<Real>::Dot (Real fX0, Real fY0, Real fX1, Real fY1)
00138 {
00139     return fX0*fX1 + fY0*fY1;
00140 }
00141 //----------------------------------------------------------------------------
00142 template <class Real>
00143 Real Query2<Real>::Det2 (Real fX0, Real fY0, Real fX1, Real fY1)
00144 {
00145     return fX0*fY1 - fX1*fY0;
00146 }
00147 //----------------------------------------------------------------------------
00148 template <class Real>
00149 Real Query2<Real>::Det3 (Real fX0, Real fY0, Real fZ0, Real fX1, Real fY1,
00150     Real fZ1, Real fX2, Real fY2, Real fZ2)
00151 {
00152     Real fC00 = fY1*fZ2 - fY2*fZ1;
00153     Real fC01 = fY2*fZ0 - fY0*fZ2;
00154     Real fC02 = fY0*fZ1 - fY1*fZ0;
00155     return fX0*fC00 + fX1*fC01 + fX2*fC02;
00156 }
00157 //----------------------------------------------------------------------------
00158 } //namespace Wm4

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