SIBCVector3Dd.h

00001 //***************************************************************************************
00002 //
00003 // File supervisor: Crosswalk team
00004 //
00005 // Copyright 2008 Autodesk, Inc.  All rights reserved.  
00006 // Use of this software is subject to the terms of the Autodesk license agreement 
00007 // provided at the time of installation or download, or which otherwise accompanies 
00008 // this software in either electronic or hard copy form.
00009 //
00010 //***************************************************************************************
00011 
00012 #if (_MSC_VER > 1000) || defined(SGI_COMPILER)
00013 #pragma once
00014 #endif
00015 
00016 //******************************************************************************
00017 // Defines
00018 //******************************************************************************
00019 
00020 #ifndef _VECTOR3_H_
00021 #define _VECTOR3_H_
00022 
00023 //******************************************************************************
00024 // Includes
00025 //****************************************************************************** 
00026 #include "SIBCMathLib.h"
00027 
00028 //******************************************************************************
00029 // Typedefs
00030 //******************************************************************************
00031 
00032 //******************************************************************************
00033 // CSIBCVector3Dd | General 3D vector.
00034 //******************************************************************************
00035 
00037 
00048 class XSICOREEXPORT CSIBCVector3Dd
00049 {
00050     // Public members
00051     public:
00052 
00053         //****************************************
00054         // IMPLEMENTATION
00055         //****************************************
00056 
00060         CSIBCVector3Dd( );
00061 
00069         CSIBCVector3Dd( const double  in_dX, const double in_dY, const double  in_dZ );
00070 
00075         CSIBCVector3Dd( const double in_dXYZ[3] );
00076 
00081         CSIBCVector3Dd( int in_nIndex, double in_dVal );
00082 
00083         ~CSIBCVector3Dd();
00084 
00085         // Old stuff support: will be removed in next release.
00086 
00093          const double * GetArray() const;
00094     
00095         // Individual access to private members
00096 
00104         double GetX( void ) const;
00105 
00113         double GetY( void ) const;
00114 
00122         double GetZ( void ) const;
00123 
00132         double Get( const int in_nIndex ) const;
00133 
00134 
00144         void Get( double& out_dX, double& out_dY, double& out_dZ ) const;
00145 
00155         double GetMaxComponent( bool in_bInAbs = true ) const;
00156 
00166         double GetMinComponent( bool in_bInAbs = true ) const;
00167 
00176         int GetIndexOfMaxComponent( bool in_bInAbs = true ) const;
00177 
00186         int GetIndexOfMinComponent( bool in_bInAbs = true ) const;
00187 
00196         CSIBCVector3Dd& SetX ( const double in_dVal );
00197 
00206         CSIBCVector3Dd& SetY ( const double in_dVal );
00207 
00216         CSIBCVector3Dd& SetZ ( const double in_dVal );
00217 
00227         CSIBCVector3Dd& Set( const CSIBCVector3Dd& in_vct );
00228 
00236         CSIBCVector3Dd& Set( const int in_nIndex, const double in_dVal );
00237 
00249         CSIBCVector3Dd& Set( const double in_dX, const double in_dY,
00250             const double in_dZ );
00251 
00252 
00258         CSIBCVector3Dd& SetNull( void );
00259 
00268         bool IsNull( const double in_dEpsilon=PICO_EPS ) const;
00269 
00282         CSIBCVector3Dd& SetMinimal ( bool in_bInAbs = true, const double in_dEpsilon=PICO_EPS );
00283 
00297         CSIBCVector3Dd& SetMinimal ( const CSIBCVector3Dd &, bool in_bInAbs = true );
00298 
00309         friend bool AreAlmostEqual( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2, 
00310             const double in_dEpsilon = PICO_EPS ) ;
00311 
00319         bool operator == ( const CSIBCVector3Dd& in_vct ) const;
00320 
00328         bool operator != ( const CSIBCVector3Dd& in_vct ) const;
00329 
00335         CSIBCVector3Dd& Negate( const CSIBCVector3Dd& in_vct );
00336 
00341         CSIBCVector3Dd& Negate( void );
00342 
00349         double GetSquaredLength( void ) const;
00350 
00357         double GetLength( void ) const;
00358 
00366         bool SetLength( const double in_dLength );
00367 
00374         bool Normalize( void );
00375 
00376 
00377         // Efficient arithmetic operations.
00378 
00385         CSIBCVector3Dd& Add( const CSIBCVector3Dd&  in_vct  );
00386 
00394         CSIBCVector3Dd& Add( const CSIBCVector3Dd&  in_vct1, const CSIBCVector3Dd& in_vct2 );
00395 
00402         CSIBCVector3Dd& Sub( const CSIBCVector3Dd& in_vct );
00403 
00411         CSIBCVector3Dd& Sub( const CSIBCVector3Dd&  in_vct1, const CSIBCVector3Dd& in_vct2 );
00412 
00422         CSIBCVector3Dd& Mul( const double in_dFactor );
00423 
00434         CSIBCVector3Dd& Mul( const double in_dFactor, const CSIBCVector3Dd& in_vct );
00435 
00446         CSIBCVector3Dd& Mul( const CSIBCVector3Dd& in_vct, const double in_dFactor );
00447 
00458         CSIBCVector3Dd& Mul( const CSIBCVector3Dd& in_vct, const CSIBCMatrix33d& in_mat );
00459 
00470         CSIBCVector3Dd& Mul( const CSIBCMatrix33d& in_mat );
00471 
00482         CSIBCVector3Dd& Mul( const CSIBCMatrix33d& in_mat, const CSIBCVector3Dd& in_vct );
00483 
00484         // TODO  Remove set of functions to multiply by CSIBCRotMatd as soon as 
00485         //       CSIBCRotMatd and CSIBCMatrix33d will both derived public from a
00486         //       common base matrix class.
00487 
00498         CSIBCVector3Dd& Mul( const CSIBCVector3Dd& in_vct, const CSIBCRotMatd& in_mat );
00499 
00510         CSIBCVector3Dd& Mul( const CSIBCRotMatd& in_mat, const CSIBCVector3Dd& in_vct );
00511 
00525         CSIBCVector3Dd& Mul( const CSIBCVector3Dd& in_vct, const CSIBCXfoMatd& in_mat );
00526 
00539         CSIBCVector3Dd& Mul( const CSIBCVector3Dd& in_vct, const CSIBCMatrix44d& in_mat );
00540 
00550         CSIBCVector3Dd& Div( const double in_dFactor );
00551 
00562         CSIBCVector3Dd& Div( const CSIBCVector3Dd& in_vct, const double in_dFactor );
00563 
00574         CSIBCVector3Dd& MulComp( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2  );
00575 
00585         CSIBCVector3Dd& MulComp( const CSIBCVector3Dd& in_vct );
00586 
00596         CSIBCVector3Dd& DivComp( const CSIBCVector3Dd& in_vct ); 
00597 
00608         CSIBCVector3Dd& DivComp( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
00609         
00610 
00617         friend double GetDot( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
00618 
00626         CSIBCVector3Dd& SetCross( const CSIBCVector3Dd& in_vct );
00627 
00635         CSIBCVector3Dd& SetCross( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
00636 
00649         bool SetOrthogonal( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
00650 
00664         bool SetOrthoProj( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
00665 
00677         friend bool AreOrthogonal( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2, 
00678             const double in_dEpsilon = PICO_EPS );
00679 
00686         bool SetProjection( const CSIBCVector3Dd& in_vct );
00687 
00695         friend bool AreParallel( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2, 
00696             const double in_dEpsilon = PICO_EPS );
00697 
00704         CSIBCVector3Dd& SetMirror( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
00705 
00713         friend double GetDistance( const CSIBCVector3Dd& in_pnt1, const CSIBCVector3Dd& in_pnt2 );
00714 
00722         friend double GetSquaredDistance( const CSIBCVector3Dd& in_pnt1, const CSIBCVector3Dd& in_pnt2 );
00723 
00733         friend void GetOrthogonalBasis( const CSIBCVector3Dd& in_vct1, CSIBCVector3Dd& out_vct2, 
00734             CSIBCVector3Dd& out_vct3 );
00735 
00747         friend void GetOrthonormalBasis( CSIBCVector3Dd& io_vct1, CSIBCVector3Dd& out_vct2, 
00748             CSIBCVector3Dd& out_vct3 );
00749 
00757         CSIBCVector3Dd& SetMidpoint( const CSIBCVector3Dd& in_pnt1, const CSIBCVector3Dd& in_pnt2 );
00758 
00759 
00768         CSIBCVector3Dd& SetMean (   const CSIBCVector3Dd *in_vct, ULONG in_nbVct );
00769 
00778         CSIBCVector3Dd& LinearPositionInterpolate( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2, const double in_dT );
00779 
00793         friend double GetPntsAngle( const CSIBCVector3Dd& in_pntOrigin,
00794                                     const CSIBCVector3Dd& in_pnt1,
00795                                     const CSIBCVector3Dd& in_pnt2 );
00796 
00812         friend double Get2DPntsAngleSigned( const CSIBCVector3Dd& in_pntOrigin,
00813                                             const CSIBCVector3Dd& in_pnt1,
00814                                             const CSIBCVector3Dd& in_pnt2 );
00815 
00829         friend double GetPntsCosAngle(  const CSIBCVector3Dd& in_pntOrigin,
00830                                         const CSIBCVector3Dd& in_pnt1,
00831                                         const CSIBCVector3Dd& in_pnt2 );
00832 
00846         friend double GetVctsAngle( const CSIBCVector3Dd&   in_vct1,
00847                                     const CSIBCVector3Dd&   in_vct2,
00848                                     const double in_dEpsilon = PICO_EPS );
00849 
00864         friend double Get2DVctsAngleSigned( const CSIBCVector3Dd& in_vct1,
00865                                             const CSIBCVector3Dd& in_vct2 );
00866 
00867         
00879         friend double GetVctsCosAngle(  const CSIBCVector3Dd& in_vct1,
00880                                         const CSIBCVector3Dd& in_vct2,
00881                                         const double in_dEpsilon = PICO_EPS );
00882 
00883 
00891         friend int Get2DPntSide(    const CSIBCVector3Dd& in_pnt,
00892                                     const CSIBCVector3Dd& in_pntOrigin,
00893                                     const CSIBCVector3Dd& in_pntTip );
00894 
00895 
00902         friend double GetTriangleArea( 
00903             const CSIBCVector3Dd& in_rPoint0,
00904             const CSIBCVector3Dd& in_rPoint1,
00905             const CSIBCVector3Dd& in_rPoint2 );
00906 
00908         // To be implemented later //
00910 
00911         // Cardinal & Bezier Position Interpolate doens't exist in SI3D3.7
00912         // What about Linear, Cardinal & Bezier VectorInterpolate
00913 
00914         // SetBounds    | Readjust boundaries (min and max) to contain a given point.
00916         void SetBounds( const CSIBCVector3Dd& in_pnt, CSIBCVector3Dd& io_min, CSIBCVector3Dd& io_max );
00917 
00918         // Combine      | Compute this=s1*v1 + s2*v2.
00920         CSIBCVector3Dd& Combine( const CSIBCVector3Dd& in_vct1, const double in_dS1, 
00921             const CSIBCVector3Dd& in_vct2, const double in_dS2 );
00922 
00923 #ifdef _DEBUG
00924          void SelfDebug() const;
00925          void DoDebugInit();
00926 #endif
00927 
00929         // To finish implementing    //
00931         
00932         // BsplinePositionInterpolate | Interpolates a BSpline position between four 3D vectors.
00934         CSIBCVector3Dd& BsplinePositionInterpolate( const CSIBCVector3Dd& in_vct1,
00935                                     const CSIBCVector3Dd& in_vct2, const CSIBCVector3Dd& in_vct3,
00936                                     const CSIBCVector3Dd& in_vct4, const double in_dT );
00937 
00938         // BsplineVectorInterpolate | Interpolates a BSpline vector between four 3D vectors.
00940         CSIBCVector3Dd& BsplineVectorInterpolate( const CSIBCVector3Dd& in_vct1,
00941                                     const CSIBCVector3Dd& in_vct2, const CSIBCVector3Dd& in_vct3,
00942                                     const CSIBCVector3Dd& in_vct4, const double in_dT );
00943 
00944         // ArePntsCollinear | Verify if three points are collinear.
00946         friend bool ArePntsCollinear( const CSIBCVector3Dd& in_pnt1,
00947                                         const CSIBCVector3Dd& in_pnt2,
00948                                         const CSIBCVector3Dd& in_pnt3,
00949                                         const double in_dEpsilon = PICO_EPS );
00950 
00951         // AreVctsCoplanar  | Verify if two vectors are coplanar.
00953         friend bool AreVctsCoplanar ( const CSIBCVector3Dd& in_vct1,
00954                                         const CSIBCVector3Dd& in_vct2,
00955                                         const CSIBCVector3Dd& in_vct3,
00956                                         const double in_dEpsilon = PICO_EPS );
00957 
00958         // ArePntsCoplanar  | Verify if three points are coplanar.
00960         friend bool ArePntsCoplanar ( const CSIBCVector3Dd& in_pnt1,
00961                                         const CSIBCVector3Dd& in_pnt2,
00962                                         const CSIBCVector3Dd& in_pnt3,
00963                                         const CSIBCVector3Dd& in_pnt4,
00964                                         const double in_dEpsilon = PICO_EPS );
00965 
00966     // Private Members
00967     private:
00968 
00969         //****************************************
00970         // ATTRIBUTES
00971         //****************************************
00972         // double | CSIBCVector3Dd | m_dX | X component of the vector.
00973         // double | CSIBCVector3Dd | m_dY | Y component of the vector.
00974         // double | CSIBCVector3Dd | m_dZ | Z component of the vector.
00975         double  m_dX, m_dY, m_dZ;
00976 
00977     public:
00978 
00980     // Useful constants:
00982     static const CSIBCVector3Dd k_UnitVector;
00983 };
00984 
00985 typedef CSIBCVector3Dd* LP3DVECTOR3;
00986 
00987 //******************************************************************************
00988 //
00989 // Author       : Michel Carigan
00990 // Date         : 08/05/96
00991 // Updated by   : Eric Cabot (02/25/97)
00992 //
00993 // Set each component to be at least epsilon (in absolute or not depending on in_bInAbs).
00994 //
00995 // A reference on this.
00996 //
00997 // This function works like the macro _SI_VCT_EPS in v3.51
00998 // That is, each component are set to eps only if they are less than epsilon.
00999 // In that case the sign is unchanged.
01000 //
01001 //
01002 //******************************************************************************
01003 inline  CSIBCVector3Dd&  
01004 CSIBCVector3Dd::SetMinimal
01005     (
01006         bool in_bInAbs,             // Tells if the test is done in absolute value or not (true by default).
01007         const double in_dEpsilon    // The epsilon to compare with (PICO_EPS by default).
01008     )
01009 {
01010 
01011     if( in_bInAbs )
01012     {
01013 
01014         if( fabs(m_dX) < in_dEpsilon )
01015             m_dX = ( ( m_dX >= 0 ) ? in_dEpsilon : -in_dEpsilon ) ;
01016         if( fabs(m_dY) < in_dEpsilon )
01017             m_dY = ( ( m_dY >= 0 ) ? in_dEpsilon : -in_dEpsilon ) ;
01018         if( fabs(m_dZ) < in_dEpsilon )
01019             m_dZ = ( ( m_dZ >= 0 ) ? in_dEpsilon : -in_dEpsilon ) ;
01020     }
01021     else
01022     {
01023         if( m_dX < in_dEpsilon )
01024         {
01025             m_dX = in_dEpsilon;
01026         }
01027         if( m_dY < in_dEpsilon )
01028         {
01029             m_dY = in_dEpsilon;
01030         }
01031         if( m_dZ < in_dEpsilon )
01032         {
01033             m_dZ = in_dEpsilon;
01034         }
01035     }
01036 
01037     return *this;
01038 }
01039 
01040 #endif