xsi_line.h Source File
 
 
 
xsi_line.h
Go to the documentation of this file.
00001 //*****************************************************************************
00011 //*****************************************************************************
00012 
00013 #if (_MSC_VER > 1000) || defined(SGI_COMPILER)
00014 #pragma once
00015 #endif
00016 
00017 #ifndef __XSILINE_H__
00018 #define __XSILINE_H__
00019 
00020 #include "sicppsdk.h"
00021 #include "xsi_status.h"
00022 #include "xsi_vector3.h"
00023 #include <math.h>
00024 
00025 namespace XSI {
00026 
00027 namespace MATH {
00028 
00029 //*****************************************************************************
00039 //*****************************************************************************
00040 class SICPPSDKDECL CLine
00041 {
00042 public:
00044         SICPPSDK_INLINE CLine();
00045 
00050         SICPPSDK_INLINE CLine( const CVector3 &in_point, const CVector3 &in_tangent );
00051 
00055         SICPPSDK_INLINE CLine( const CLine &in_line );
00056 
00058         SICPPSDK_INLINE ~CLine();
00059 
00064         SICPPSDK_INLINE CLine & operator=( const CLine & in_line );
00065 
00071         SICPPSDK_INLINE bool operator ==(const CLine &in_line )const;
00072 
00078         SICPPSDK_INLINE bool operator !=(const CLine &in_line )const;
00079 
00086         SICPPSDK_INLINE bool EpsilonEquals(const CLine &in_line, double in_dEpsilon)const;
00087 
00092         SICPPSDK_INLINE bool Equals(const CLine &in_line)const;
00093 
00098         bool Parallel(const CLine &in_line)const;
00099 
00104         bool Collinear(const CLine &in_line)const;
00105 
00109         SICPPSDK_INLINE CVector3 Project(const CVector3 &in_point)const;
00110 
00114         SICPPSDK_INLINE CVector3 GetClosestPoint(const CLine &in_line)const;
00115 
00119         SICPPSDK_INLINE double GetDistance(const CVector3 &in_point)const;
00120 
00124         SICPPSDK_INLINE double GetDistance(const CLine &in_line)const;
00125 
00130         SICPPSDK_INLINE CVector3 GetPosition(double in_param)const;
00131 
00135         double GetParameter(const CVector3 &in_point)const;
00136 
00142         bool Intersect(const CLine &in_line, CVector3 &out_point)const;
00143 
00147         SICPPSDK_INLINE const CVector3 &GetOrigin()const;
00148 
00152         SICPPSDK_INLINE const CVector3 &GetTangent()const;
00153 
00158         SICPPSDK_INLINE CLine &SetOrigin(const CVector3 &in_point);
00159 
00164         SICPPSDK_INLINE CLine &SetTangent(const CVector3 &in_tangent);
00165 
00171         SICPPSDK_INLINE CLine &Set(const CVector3 &in_point, const CVector3 &in_tangent);
00172 
00178         SICPPSDK_INLINE CLine& operator *=(const CMatrix3& in_matrix3);
00179 
00185         SICPPSDK_INLINE CLine& operator *=(const CMatrix4& in_matrix4);
00186 
00192         SICPPSDK_INLINE CLine& operator *=(const CTransformation& in_transformation);
00193 
00198         SICPPSDK_INLINE CLine& MulByMatrix3InPlace(const CMatrix3& in_matrix3);
00199 
00205         SICPPSDK_INLINE CLine& MulByMatrix3(const CLine &in_line, const CMatrix3 &in_matrix3);
00206 
00211         SICPPSDK_INLINE CLine& MulByMatrix4InPlace(const CMatrix4& in_matrix4);
00212 
00218         SICPPSDK_INLINE CLine& MulByMatrix4(const CLine &in_line, const CMatrix4 &in_matrix4);
00219 
00224         SICPPSDK_INLINE CLine& MulByTransformationInPlace(const CTransformation &in_transformation);
00225 
00231         SICPPSDK_INLINE CLine& MulByTransformation(const CLine &in_line, const CTransformation &in_transformation);
00232 
00233 private:
00234         CVector3        m_vOrigin;
00235         CVector3        m_vTangent;
00236 };
00237 
00238 //inline functions
00239 SICPPSDK_INLINE CLine::CLine()
00240 : m_vOrigin(0.0, 0.0, 0.0), m_vTangent(1.0, 0.0, 0.0)
00241 {
00242 }
00243 
00244 SICPPSDK_INLINE CLine::CLine( const CLine& in_line )
00245 : m_vOrigin(in_line.m_vOrigin), m_vTangent(in_line.m_vTangent)
00246 {
00247 }
00248 
00249 SICPPSDK_INLINE CLine::CLine( const CVector3 &in_pt, const CVector3 &in_dir )
00250 : m_vOrigin(in_pt), m_vTangent(in_dir)
00251 {}
00252 
00253 SICPPSDK_INLINE CLine::~CLine()
00254 {}
00255 
00256 SICPPSDK_INLINE CLine& CLine::operator=( const CLine & in_line )
00257 {
00258         m_vOrigin = in_line.m_vOrigin;
00259         m_vTangent = in_line.m_vTangent;
00260         return *this;
00261 }
00262 
00263 SICPPSDK_INLINE const CVector3 &CLine::GetOrigin()const
00264 {
00265         return m_vOrigin;
00266 }
00267 
00268 SICPPSDK_INLINE const CVector3 &CLine::GetTangent()const
00269 {
00270         return m_vTangent;
00271 }
00272 
00273 SICPPSDK_INLINE bool CLine::EpsilonEquals(const CLine& in_line, double in_dEpsilon)const
00274 {
00275         return (this == &in_line ? true :
00276                         (m_vOrigin.EpsilonEquals(in_line.m_vOrigin, in_dEpsilon) &&
00277                          m_vTangent.EpsilonEquals(in_line.m_vTangent, in_dEpsilon)));
00278 }
00279 
00280 
00281 SICPPSDK_INLINE bool CLine::Equals(const CLine& in_line)const
00282 {
00283         return (this == &in_line ? true :
00284                         (m_vOrigin.Equals(in_line.m_vOrigin) &&
00285                          m_vTangent.Equals(in_line.m_vTangent)));
00286 }
00287 
00288 SICPPSDK_INLINE bool CLine::operator ==(const CLine & in_line )const
00289 {
00290         return Equals(in_line);
00291 }
00292 
00293 SICPPSDK_INLINE bool CLine::operator !=(const CLine & in_line )const
00294 {
00295         return !Equals(in_line);
00296 }
00297 
00298 SICPPSDK_INLINE CVector3 CLine::GetPosition(double in_param)const
00299 {
00300         CVector3 l_Result;
00301         l_Result.ScaleAdd( in_param, m_vTangent, m_vOrigin );
00302         return l_Result;
00303 }
00304 
00305 SICPPSDK_INLINE CLine & CLine::SetOrigin(const CVector3 &in_point)
00306 {
00307         m_vOrigin = in_point;
00308         return *this;
00309 }
00310 
00311 SICPPSDK_INLINE CLine &CLine::SetTangent(const CVector3 &in_tangent)
00312 {
00313         m_vTangent = in_tangent;
00314         return *this;
00315 }
00316 
00317 SICPPSDK_INLINE CLine & CLine::Set(const CVector3 &in_point, const CVector3 &in_tangent)
00318 {
00319         m_vOrigin = in_point;
00320         m_vTangent = in_tangent;
00321         return *this;
00322 }
00323 
00324 SICPPSDK_INLINE CVector3 CLine::Project(const CVector3 &in_point)const
00325 {
00326         return GetPosition(GetParameter(in_point));
00327 }
00328 
00329 SICPPSDK_INLINE CVector3 CLine::GetClosestPoint(const CLine &in_line)const
00330 {
00331         CVector3 l_Closest;
00332         Intersect( in_line, l_Closest );
00333         return l_Closest;
00334 }
00335 
00336 SICPPSDK_INLINE double CLine::GetDistance(const CVector3 &in_point)const
00337 {
00338         return Project(in_point).SubInPlace(in_point).GetLength();
00339 }
00340 
00341 SICPPSDK_INLINE double CLine::GetDistance(const CLine &in_line)const
00342 {
00343         CVector3 l_Tmp;
00344         return ( Intersect( in_line, l_Tmp ) ? 0.0 : GetDistance( in_line.m_vOrigin ) );
00345 }
00346 
00347 SICPPSDK_INLINE CLine& CLine::MulByMatrix3(const CLine& in_line, const CMatrix3& in_matrix3)
00348 {
00349         CVector3 l_NewOrigin, l_NewTangent;
00350         l_NewOrigin.MulByMatrix3(in_line.m_vOrigin, in_matrix3);
00351         l_NewTangent.Add(in_line.m_vOrigin, in_line.m_vTangent);
00352         l_NewTangent.MulByMatrix3InPlace(in_matrix3);
00353         l_NewTangent.SubInPlace(l_NewOrigin);
00354         return Set(l_NewOrigin, l_NewTangent);
00355 }
00356 
00357 SICPPSDK_INLINE CLine& CLine::MulByMatrix4(const CLine& in_line, const CMatrix4& in_matrix4)
00358 {
00359         CVector3 l_NewOrigin, l_NewTangent;
00360         l_NewOrigin.MulByMatrix4(in_line.m_vOrigin, in_matrix4);
00361         l_NewTangent.Add(in_line.m_vOrigin, in_line.m_vTangent);
00362         l_NewTangent.MulByMatrix4InPlace(in_matrix4);
00363         l_NewTangent.SubInPlace(l_NewOrigin);
00364         return Set(l_NewOrigin, l_NewTangent);
00365 }
00366 
00367 SICPPSDK_INLINE CLine& CLine::MulByTransformation(const CLine &in_line, const CTransformation &in_transformation)
00368 {
00369         CVector3 l_NewOrigin, l_NewTangent;
00370         l_NewOrigin.MulByTransformation(in_line.m_vOrigin, in_transformation);
00371         l_NewTangent.Add(in_line.m_vOrigin, in_line.m_vTangent);
00372         l_NewTangent.MulByTransformationInPlace(in_transformation);
00373         l_NewTangent.SubInPlace(l_NewOrigin);
00374         return Set(l_NewOrigin, l_NewTangent);
00375 }
00376 
00377 SICPPSDK_INLINE CLine& CLine::MulByMatrix3InPlace(const CMatrix3& in_matrix3)
00378 {
00379         return MulByMatrix3(*this, in_matrix3);
00380 }
00381 
00382 SICPPSDK_INLINE CLine& CLine::MulByMatrix4InPlace(const CMatrix4& in_matrix4)
00383 {
00384         return MulByMatrix4(*this, in_matrix4);
00385 }
00386 
00387 SICPPSDK_INLINE CLine& CLine::MulByTransformationInPlace(const CTransformation& in_crTrans)
00388 {
00389         return MulByTransformation(*this, in_crTrans);
00390 }
00391 
00392 SICPPSDK_INLINE CLine& CLine::operator *=(const CMatrix3& in_matrix3)
00393 {
00394         return MulByMatrix3InPlace(in_matrix3);
00395 }
00396 
00397 SICPPSDK_INLINE CLine& CLine::operator *=(const CMatrix4& in_matrix4)
00398 {
00399         return MulByMatrix4InPlace(in_matrix4);
00400 }
00401 
00402 SICPPSDK_INLINE CLine& CLine::operator *=(const CTransformation& in_transformation)
00403 {
00404         return MulByTransformationInPlace(in_transformation);
00405 }
00406 
00407 };
00408 };
00409 
00410 #endif // __XSILINE_H__