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 #include "Wm4FoundationPCH.h" 00018 #include "Wm4IntrLine3Plane3.h" 00019 00020 namespace Wm4 00021 { 00022 //---------------------------------------------------------------------------- 00023 template <class Real> 00024 IntrLine3Plane3<Real>::IntrLine3Plane3 (const Line3<Real>& rkLine, 00025 const Plane3<Real>& rkPlane) 00026 : 00027 m_rkLine(rkLine), 00028 m_rkPlane(rkPlane) 00029 { 00030 } 00031 //---------------------------------------------------------------------------- 00032 template <class Real> 00033 const Line3<Real>& IntrLine3Plane3<Real>::GetLine () const 00034 { 00035 return m_rkLine; 00036 } 00037 //---------------------------------------------------------------------------- 00038 template <class Real> 00039 const Plane3<Real>& IntrLine3Plane3<Real>::GetPlane () const 00040 { 00041 return m_rkPlane; 00042 } 00043 //---------------------------------------------------------------------------- 00044 template <class Real> 00045 bool IntrLine3Plane3<Real>::Test () 00046 { 00047 Real fDdN = m_rkLine.Direction.Dot(m_rkPlane.Normal); 00048 if (Math<Real>::FAbs(fDdN) > Math<Real>::ZERO_TOLERANCE) 00049 { 00050 // The line is not parallel to the plane, so they must intersect. 00051 // The line parameter is *not* set, since this is a test-intersection 00052 // query. 00053 m_iIntersectionType = IT_POINT; 00054 return true; 00055 } 00056 00057 // The line and plane are parallel. Determine if they are numerically 00058 // close enough to be coincident. 00059 Real fSDistance = m_rkPlane.DistanceTo(m_rkLine.Origin); 00060 if (Math<Real>::FAbs(fSDistance) <= Math<Real>::ZERO_TOLERANCE) 00061 { 00062 m_iIntersectionType = IT_LINE; 00063 return true; 00064 } 00065 00066 m_iIntersectionType = IT_EMPTY; 00067 return false; 00068 } 00069 //---------------------------------------------------------------------------- 00070 template <class Real> 00071 bool IntrLine3Plane3<Real>::Find () 00072 { 00073 Real fDdN = m_rkLine.Direction.Dot(m_rkPlane.Normal); 00074 Real fSDistance = m_rkPlane.DistanceTo(m_rkLine.Origin); 00075 if (Math<Real>::FAbs(fDdN) > Math<Real>::ZERO_TOLERANCE) 00076 { 00077 // The line is not parallel to the plane, so they must intersect. 00078 m_fLineT = -fSDistance/fDdN; 00079 m_iIntersectionType = IT_POINT; 00080 return true; 00081 } 00082 00083 // The Line and plane are parallel. Determine if they are numerically 00084 // close enough to be coincident. 00085 if (Math<Real>::FAbs(fSDistance) <= Math<Real>::ZERO_TOLERANCE) 00086 { 00087 // The line is coincident with the plane, so choose t = 0 for the 00088 // parameter. 00089 m_fLineT = (Real)0.0; 00090 m_iIntersectionType = IT_LINE; 00091 return true; 00092 } 00093 00094 m_iIntersectionType = IT_EMPTY; 00095 return false; 00096 } 00097 //---------------------------------------------------------------------------- 00098 template <class Real> 00099 Real IntrLine3Plane3<Real>::GetLineT () const 00100 { 00101 return m_fLineT; 00102 } 00103 //---------------------------------------------------------------------------- 00104 00105 //---------------------------------------------------------------------------- 00106 // explicit instantiation 00107 //---------------------------------------------------------------------------- 00108 template WM4_FOUNDATION_ITEM 00109 class IntrLine3Plane3<float>; 00110 00111 template WM4_FOUNDATION_ITEM 00112 class IntrLine3Plane3<double>; 00113 //---------------------------------------------------------------------------- 00114 }