Wm4QuadricSurface.h

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 #ifndef WM4QUADRICSURFACE_H
00018 #define WM4QUADRICSURFACE_H
00019 
00020 #include "Wm4FoundationLIB.h"
00021 #include "Wm4ImplicitSurface.h"
00022 #include "Wm4RVector3.h"
00023 
00024 namespace Wm4
00025 {
00026 
00027 template <class Real>
00028 class WM4_FOUNDATION_ITEM QuadricSurface : public ImplicitSurface<Real>
00029 {
00030 public:
00031     // A quadric surface is defined implicitly by
00032     //
00033     //   0 = a0 + a1*x[0] + a2*x[1] + a3*x[2] + a4*x[0]^2 + a5*x[0]*x[1] +
00034     //       a6*x[0]*x[2] + a7*x[1]^2 + a8*x[1]*x[2] + a9*x[2]^2
00035     //
00036     //     = a0 + [a1 a2 a3]*X + X^T*[a4   a5/2 a6/2]*X
00037     //                               [a5/2 a7   a8/2]
00038     //                               [a6/2 a8/2 a9  ]
00039     //     = C + B^T*X + X^T*A*X
00040     //
00041     // The matrix A is symmetric.
00042 
00043     QuadricSurface ();  // all coefficients zero
00044     QuadricSurface (const Real afCoeff[10]);
00045 
00046     // member access
00047     const Real* GetCoefficients () const;
00048     const Matrix3<Real>& GetA () const;
00049     const Vector3<Real>& GetB () const;
00050     Real GetC () const;
00051 
00052     // the function
00053     virtual Real F (const Vector3<Real>& rkP) const;
00054 
00055     // first-order partial derivatives
00056     virtual Real FX (const Vector3<Real>& rkP) const;
00057     virtual Real FY (const Vector3<Real>& rkP) const;
00058     virtual Real FZ (const Vector3<Real>& rkP) const;
00059 
00060     // second-order partial derivatives
00061     virtual Real FXX (const Vector3<Real>& rkP) const;
00062     virtual Real FXY (const Vector3<Real>& rkP) const;
00063     virtual Real FXZ (const Vector3<Real>& rkP) const;
00064     virtual Real FYY (const Vector3<Real>& rkP) const;
00065     virtual Real FYZ (const Vector3<Real>& rkP) const;
00066     virtual Real FZZ (const Vector3<Real>& rkP) const;
00067 
00068     enum  // solution type
00069     {
00070         QT_NONE,
00071         QT_POINT,
00072         QT_LINE,
00073         QT_PLANE,
00074         QT_TWO_PLANES,
00075         QT_PARABOLIC_CYLINDER,
00076         QT_ELLIPTIC_CYLINDER,
00077         QT_HYPERBOLIC_CYLINDER,
00078         QT_ELLIPTIC_PARABOLOID,
00079         QT_HYPERBOLIC_PARABOLOID,
00080         QT_ELLIPTIC_CONE,
00081         QT_HYPERBOLOID_ONE_SHEET,
00082         QT_HYPERBOLOID_TWO_SHEETS,
00083         QT_ELLIPSOID
00084     };
00085 
00086     // classification of the equation using exact arithmetic
00087     int GetType () const;
00088 
00089 protected:
00090     Real m_afCoeff[10];
00091     Matrix3<Real> m_kA;
00092     Vector3<Real> m_kB;
00093     Real m_fC;
00094 
00095 private:
00096     typedef TRational<4*sizeof(Real)> Rational;
00097     typedef RVector3<4*sizeof(Real)> QSVector;
00098 
00099     class RReps
00100     {
00101     public:
00102         RReps (const Real afCoeff[10])
00103         {
00104             Rational kOneHalf(1,2);
00105 
00106             c = Rational(afCoeff[0]);
00107             b0 = Rational(afCoeff[1]);
00108             b1 = Rational(afCoeff[2]);
00109             b2 = Rational(afCoeff[3]);
00110             a00 = Rational(afCoeff[4]);
00111             a01 = kOneHalf*Rational(afCoeff[5]);
00112             a02 = kOneHalf*Rational(afCoeff[6]);
00113             a11 = Rational(afCoeff[7]);
00114             a12 = kOneHalf*Rational(afCoeff[8]);
00115             a22 = Rational(afCoeff[9]);
00116 
00117             Sub00 = a11*a22 - a12*a12;
00118             Sub01 = a01*a22 - a12*a02;
00119             Sub02 = a01*a12 - a02*a11;
00120             Sub11 = a00*a22 - a02*a02;
00121             Sub12 = a00*a12 - a02*a01;
00122             Sub22 = a00*a11 - a01*a01;
00123             c0 = a00*Sub00 - a01*Sub01 + a02*Sub02;
00124             c1 = Sub00 + Sub11 + Sub22;
00125             c2 = a00 + a11 + a22;
00126         }
00127 
00128         // quadratic coefficients
00129         Rational a00, a01, a02, a11, a12, a22, b0, b1, b2, c;
00130 
00131         // 2-by-2 determinants
00132         Rational Sub00, Sub01, Sub02, Sub11, Sub12, Sub22;
00133 
00134         // characteristic polynomial L^3 - C2*L^2 + C1*L - C0
00135         Rational c0, c1, c2;
00136 
00137         // for Sturm sequences
00138         Rational c3, c4, c5;
00139     };
00140 
00141     static void GetRootSigns (RReps& rkReps, int& riPositiveRoots,
00142         int& riNegativeRoots, int& riZeroRoots);
00143     static int GetSignChanges (int iQuantity, const Rational* akValue);
00144     static int ClassifyZeroRoots0 (const RReps& rkReps, int iPositiveRoots);
00145     static int ClassifyZeroRoots1 (const RReps& rkReps, int iPositiveRoots);
00146     static int ClassifyZeroRoots1 (const RReps& rkReps, int iPositiveRoots,
00147         const QSVector& rkP0, const QSVector& rkP1, const QSVector& rkP2);
00148     static int ClassifyZeroRoots2 (const RReps& rkReps, int iPositiveRoots);
00149     static int ClassifyZeroRoots2 (const RReps& rkReps, int iPositiveRoots,
00150         const QSVector& rkP0, const QSVector& rkP1, const QSVector& rkP2);
00151     static int ClassifyZeroRoots3 (const RReps& rkReps);
00152 };
00153 
00154 typedef QuadricSurface<float> QuadricSurfacef;
00155 typedef QuadricSurface<double> QuadricSurfaced;
00156 
00157 }
00158 
00159 #endif

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