Wm4Query3TInteger.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 Query3TInteger<Real>::Query3TInteger (int iVQuantity,
00022     const Vector3<Real>* akVertex)
00023     :
00024     Query3<Real>(iVQuantity,akVertex)
00025 {
00026 }
00027 //----------------------------------------------------------------------------
00028 template <class Real>
00029 Query::Type Query3TInteger<Real>::GetType () const
00030 {
00031     return Query::QT_INTEGER;
00032 }
00033 //----------------------------------------------------------------------------
00034 template <class Real>
00035 int Query3TInteger<Real>::ToPlane (const Vector3<Real>& rkP, int iV0, int iV1,
00036     int iV2) const
00037 {
00038     const Vector3<Real>& rkV0 = m_akVertex[iV0];
00039     const Vector3<Real>& rkV1 = m_akVertex[iV1];
00040     const Vector3<Real>& rkV2 = m_akVertex[iV2];
00041 
00042     TInteger<4> kX0((int)rkP[0] - (int)rkV0[0]);
00043     TInteger<4> kY0((int)rkP[1] - (int)rkV0[1]);
00044     TInteger<4> kZ0((int)rkP[2] - (int)rkV0[2]);
00045     TInteger<4> kX1((int)rkV1[0] - (int)rkV0[0]);
00046     TInteger<4> kY1((int)rkV1[1] - (int)rkV0[1]);
00047     TInteger<4> kZ1((int)rkV1[2] - (int)rkV0[2]);
00048     TInteger<4> kX2((int)rkV2[0] - (int)rkV0[0]);
00049     TInteger<4> kY2((int)rkV2[1] - (int)rkV0[1]);
00050     TInteger<4> kZ2((int)rkV2[2] - (int)rkV0[2]);
00051 
00052     TInteger<4> kDet3 = Det3(kX0,kY0,kZ0,kX1,kY1,kZ1,kX2,kY2,kZ2);
00053     return (kDet3 > 0 ? +1 : (kDet3 < 0 ? -1 : 0));
00054 }
00055 //----------------------------------------------------------------------------
00056 template <class Real>
00057 int Query3TInteger<Real>::ToCircumsphere (const Vector3<Real>& rkP, int iV0,
00058     int iV1, int iV2, int iV3) const
00059 {
00060     const Vector3<Real>& rkV0 = m_akVertex[iV0];
00061     const Vector3<Real>& rkV1 = m_akVertex[iV1];
00062     const Vector3<Real>& rkV2 = m_akVertex[iV2];
00063     const Vector3<Real>& rkV3 = m_akVertex[iV3];
00064 
00065     int aiP[3] = { (int)rkP[0], (int)rkP[1], (int)rkP[2] };
00066     int aiV0[3] = { (int)rkV0[0], (int)rkV0[1], (int)rkV0[2] };
00067     int aiV1[3] = { (int)rkV1[0], (int)rkV1[1], (int)rkV1[2] };
00068     int aiV2[3] = { (int)rkV2[0], (int)rkV2[1], (int)rkV2[2] };
00069     int aiV3[3] = { (int)rkV3[0], (int)rkV3[1], (int)rkV3[2] };
00070 
00071     TInteger<6> kS0x(aiV0[0] + aiP[0]);
00072     TInteger<6> kD0x(aiV0[0] - aiP[0]);
00073     TInteger<6> kS0y(aiV0[1] + aiP[1]);
00074     TInteger<6> kD0y(aiV0[1] - aiP[1]);
00075     TInteger<6> kS0z(aiV0[2] + aiP[2]);
00076     TInteger<6> kD0z(aiV0[2] - aiP[2]);
00077     TInteger<6> kS1x(aiV1[0] + aiP[0]);
00078     TInteger<6> kD1x(aiV1[0] - aiP[0]);
00079     TInteger<6> kS1y(aiV1[1] + aiP[1]);
00080     TInteger<6> kD1y(aiV1[1] - aiP[1]);
00081     TInteger<6> kS1z(aiV1[2] + aiP[2]);
00082     TInteger<6> kD1z(aiV1[2] - aiP[2]);
00083     TInteger<6> kS2x(aiV2[0] + aiP[0]);
00084     TInteger<6> kD2x(aiV2[0] - aiP[0]);
00085     TInteger<6> kS2y(aiV2[1] + aiP[1]);
00086     TInteger<6> kD2y(aiV2[1] - aiP[1]);
00087     TInteger<6> kS2z(aiV2[2] + aiP[2]);
00088     TInteger<6> kD2z(aiV2[2] - aiP[2]);
00089     TInteger<6> kS3x(aiV3[0] + aiP[0]);
00090     TInteger<6> kD3x(aiV3[0] - aiP[0]);
00091     TInteger<6> kS3y(aiV3[1] + aiP[1]);
00092     TInteger<6> kD3y(aiV3[1] - aiP[1]);
00093     TInteger<6> kS3z(aiV3[2] + aiP[2]);
00094     TInteger<6> kD3z(aiV3[2] - aiP[2]);
00095     TInteger<6> kW0 = kS0x*kD0x + kS0y*kD0y + kS0z*kD0z;
00096     TInteger<6> kW1 = kS1x*kD1x + kS1y*kD1y + kS1z*kD1z;
00097     TInteger<6> kW2 = kS2x*kD2x + kS2y*kD2y + kS2z*kD2z;
00098     TInteger<6> kW3 = kS3x*kD3x + kS3y*kD3y + kS3z*kD3z;
00099     TInteger<6> kDet4 = Det4(kD0x,kD0y,kD0z,kW0,kD1x,kD1y,kD1z,kW1,kD2x,kD2y,
00100         kD2z,kW2,kD3x,kD3y,kD3z,kW3);
00101 
00102     return (kDet4 > 0 ? 1 : (kDet4 < 0 ? -1 : 0));
00103 }
00104 //----------------------------------------------------------------------------
00105 template <class Real>
00106 TInteger<3> Query3TInteger<Real>::Dot (TInteger<3>& rkX0, TInteger<3>& rkY0,
00107     TInteger<3>& rkZ0, TInteger<3>& rkX1, TInteger<3>& rkY1,
00108     TInteger<3>& rkZ1)
00109 {
00110     return rkX0*rkX1 + rkY0*rkY1 + rkZ0*rkZ1;
00111 }
00112 //----------------------------------------------------------------------------
00113 template <class Real>
00114 TInteger<4> Query3TInteger<Real>::Det3 (TInteger<4>& rkX0, TInteger<4>& rkY0,
00115     TInteger<4>& rkZ0, TInteger<4>& rkX1, TInteger<4>& rkY1,
00116     TInteger<4>& rkZ1, TInteger<4>& rkX2, TInteger<4>& rkY2,
00117     TInteger<4>& rkZ2)
00118 {
00119     TInteger<4> kC00 = rkY1*rkZ2 - rkY2*rkZ1;
00120     TInteger<4> kC01 = rkY2*rkZ0 - rkY0*rkZ2;
00121     TInteger<4> kC02 = rkY0*rkZ1 - rkY1*rkZ0;
00122     return rkX0*kC00 + rkX1*kC01 + rkX2*kC02;
00123 }
00124 //----------------------------------------------------------------------------
00125 template <class Real>
00126 TInteger<6> Query3TInteger<Real>::Det4 (TInteger<6>& rkX0, TInteger<6>& rkY0,
00127     TInteger<6>& rkZ0, TInteger<6>& rkW0, TInteger<6>& rkX1,
00128     TInteger<6>& rkY1, TInteger<6>& rkZ1, TInteger<6>& rkW1,
00129     TInteger<6>& rkX2, TInteger<6>& rkY2, TInteger<6>& rkZ2,
00130     TInteger<6>& rkW2, TInteger<6>& rkX3, TInteger<6>& rkY3,
00131     TInteger<6>& rkZ3, TInteger<6>& rkW3)
00132 {
00133     TInteger<6> kA0 = rkX0*rkY1 - rkX1*rkY0;
00134     TInteger<6> kA1 = rkX0*rkY2 - rkX2*rkY0;
00135     TInteger<6> kA2 = rkX0*rkY3 - rkX3*rkY0;
00136     TInteger<6> kA3 = rkX1*rkY2 - rkX2*rkY1;
00137     TInteger<6> kA4 = rkX1*rkY3 - rkX3*rkY1;
00138     TInteger<6> kA5 = rkX2*rkY3 - rkX3*rkY2;
00139     TInteger<6> kB0 = rkZ0*rkW1 - rkZ1*rkW0;
00140     TInteger<6> kB1 = rkZ0*rkW2 - rkZ2*rkW0;
00141     TInteger<6> kB2 = rkZ0*rkW3 - rkZ3*rkW0;
00142     TInteger<6> kB3 = rkZ1*rkW2 - rkZ2*rkW1;
00143     TInteger<6> kB4 = rkZ1*rkW3 - rkZ3*rkW1;
00144     TInteger<6> kB5 = rkZ2*rkW3 - rkZ3*rkW2;
00145     return kA0*kB5-kA1*kB4+kA2*kB3+kA3*kB2-kA4*kB1+kA5*kB0;
00146 }
00147 //----------------------------------------------------------------------------
00148 } //namespace Wm4

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