Wm4DistVector3Segment3.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "Wm4FoundationPCH.h"
00018 #include "Wm4DistVector3Segment3.h"
00019
00020 namespace Wm4
00021 {
00022
00023 template <class Real>
00024 DistVector3Segment3<Real>::DistVector3Segment3 (const Vector3<Real>& rkVector,
00025 const Segment3<Real>& rkSegment)
00026 :
00027 m_rkVector(rkVector),
00028 m_rkSegment(rkSegment)
00029 {
00030 }
00031
00032 template <class Real>
00033 const Vector3<Real>& DistVector3Segment3<Real>::GetVector () const
00034 {
00035 return m_rkVector;
00036 }
00037
00038 template <class Real>
00039 const Segment3<Real>& DistVector3Segment3<Real>::GetSegment () const
00040 {
00041 return m_rkSegment;
00042 }
00043
00044 template <class Real>
00045 Real DistVector3Segment3<Real>::Get ()
00046 {
00047 Real fSqrDist = GetSquared();
00048 return Math<Real>::Sqrt(fSqrDist);
00049 }
00050
00051 template <class Real>
00052 Real DistVector3Segment3<Real>::GetSquared ()
00053 {
00054 Vector3<Real> kDiff = m_rkVector - m_rkSegment.Origin;
00055 m_fSegmentParameter = m_rkSegment.Direction.Dot(kDiff);
00056
00057 if (-m_rkSegment.Extent < m_fSegmentParameter)
00058 {
00059 if (m_fSegmentParameter < m_rkSegment.Extent)
00060 {
00061 m_kClosestPoint1 = m_rkSegment.Origin +
00062 m_fSegmentParameter*m_rkSegment.Direction;
00063 }
00064 else
00065 {
00066 m_kClosestPoint1 = m_rkSegment.Origin +
00067 m_rkSegment.Extent*m_rkSegment.Direction;
00068 }
00069 }
00070 else
00071 {
00072 m_kClosestPoint1 = m_rkSegment.Origin -
00073 m_rkSegment.Extent*m_rkSegment.Direction;
00074 }
00075
00076 m_kClosestPoint0 = m_rkVector;
00077 kDiff = m_kClosestPoint1 - m_kClosestPoint0;
00078 return kDiff.SquaredLength();
00079 }
00080
00081 template <class Real>
00082 Real DistVector3Segment3<Real>::Get (Real fT,
00083 const Vector3<Real>& rkVelocity0, const Vector3<Real>& rkVelocity1)
00084 {
00085 Vector3<Real> kMVector = m_rkVector + fT*rkVelocity0;
00086 Vector3<Real> kMOrigin = m_rkSegment.Origin + fT*rkVelocity1;
00087 Segment3<Real> kMSegment(kMOrigin,m_rkSegment.Direction,
00088 m_rkSegment.Extent);
00089 return DistVector3Segment3<Real>(kMVector,kMSegment).Get();
00090 }
00091
00092 template <class Real>
00093 Real DistVector3Segment3<Real>::GetSquared (Real fT,
00094 const Vector3<Real>& rkVelocity0, const Vector3<Real>& rkVelocity1)
00095 {
00096 Vector3<Real> kMVector = m_rkVector + fT*rkVelocity0;
00097 Vector3<Real> kMOrigin = m_rkSegment.Origin + fT*rkVelocity1;
00098 Segment3<Real> kMSegment(kMOrigin,m_rkSegment.Direction,
00099 m_rkSegment.Extent);
00100 return DistVector3Segment3<Real>(kMVector,kMSegment).GetSquared();
00101 }
00102
00103 template <class Real>
00104 Real DistVector3Segment3<Real>::GetSegmentParameter () const
00105 {
00106 return m_fSegmentParameter;
00107 }
00108
00109
00110
00111
00112
00113 template WM4_FOUNDATION_ITEM
00114 class DistVector3Segment3<float>;
00115
00116 template WM4_FOUNDATION_ITEM
00117 class DistVector3Segment3<double>;
00118
00119 }