Wm4Distance.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 WM4DISTANCE_H
00018 #define WM4DISTANCE_H
00019 
00020 #include "Wm4FoundationLIB.h"
00021 #include "Wm4Vector2.h"
00022 #include "Wm4Vector3.h"
00023 
00024 namespace Wm4
00025 {
00026 
00027 template <class Real, class TVector>
00028 class WM4_FOUNDATION_ITEM Distance
00029 {
00030 public:
00031     // abstract base class
00032     virtual ~Distance ();
00033 
00034     // static distance queries
00035     virtual Real Get () = 0;     // distance
00036     virtual Real GetSquared () = 0;  // squared distance
00037 
00038     // function calculations for dynamic distance queries
00039     virtual Real Get (Real fT, const TVector& rkVelocity0,
00040         const TVector& rkVelocity1) = 0;
00041     virtual Real GetSquared (Real fT, const TVector& rkVelocity0,
00042         const TVector& rkVelocity1) = 0;
00043 
00044     // Derivative calculations for dynamic distance queries.  The defaults
00045     // use finite difference estimates
00046     //   f'(t) = (f(t+h)-f(t-h))/(2*h)
00047     // where h = DifferenceStep.  A derived class may override these and
00048     // provide implementations of exact formulas that do not require h.
00049     virtual Real GetDerivative (Real fT, const TVector& rkVelocity0,
00050         const TVector& rkVelocity1);
00051     virtual Real GetDerivativeSquared (Real fT, const TVector& rkVelocity0,
00052         const TVector& rkVelocity1);
00053 
00054     // Dynamic distance queries.  The function computes the smallest distance
00055     // between the two objects over the time interval [tmin,tmax].
00056     virtual Real Get (Real fTMin, Real fTMax, const TVector& rkVelocity0,
00057         const TVector& rkVelocity1);
00058     virtual Real GetSquared (Real fTMin, Real fTMax,
00059         const TVector& rkVelocity0, const TVector& rkVelocity1);
00060 
00061     // for Newton's method and inverse parabolic interpolation
00062     int MaximumIterations;  // default = 8
00063     Real ZeroThreshold;     // default = Math<Real>::ZERO_TOLERANCE
00064 
00065     // for derivative approximations
00066     void SetDifferenceStep (Real fDifferenceStep);  // default = 1e-03
00067     Real GetDifferenceStep () const;
00068 
00069     // The time at which minimum distance occurs for the dynamic queries.
00070     Real GetContactTime () const;
00071 
00072     // Closest points on the two objects.  These are valid for static or
00073     // dynamic queries.  The set of closest points on a single object need
00074     // not be a single point.  In this case, the Boolean member functions
00075     // return 'true'.  A derived class may support querying for the full
00076     // contact set.
00077     const TVector& GetClosestPoint0 () const;
00078     const TVector& GetClosestPoint1 () const;
00079     bool HasMultipleClosestPoints0 () const;
00080     bool HasMultipleClosestPoints1 () const;
00081 
00082 protected:
00083     Distance ();
00084 
00085     Real m_fContactTime;
00086     TVector m_kClosestPoint0;
00087     TVector m_kClosestPoint1;
00088     bool m_bHasMultipleClosestPoints0;
00089     bool m_bHasMultipleClosestPoints1;
00090     Real m_fDifferenceStep, m_fInvTwoDifferenceStep;
00091 };
00092 
00093 typedef Distance<float,Vector2f> Distance2f;
00094 typedef Distance<float,Vector3f> Distance3f;
00095 typedef Distance<double,Vector2d> Distance2d;
00096 typedef Distance<double,Vector3d> Distance3d;
00097 
00098 }
00099 
00100 #endif

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