Main Page   Class Hierarchy   Compound List   File List   Compound Members  

geVector.h

00001 //////////////////////////////////////////////////////////////////////
00002 // Copyright (c) 2001-2003 David Pritchard <drpritch@alumni.uwaterloo.ca>
00003 // 
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either
00007 // version 2 of the License, or (at your option) any later
00008 // version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 #ifndef freecloth_geom_geVector_h
00020 #define freecloth_geom_geVector_h
00021 
00022 #ifndef freecloth_geom_package_h
00023 #include <freecloth/geom/package.h>
00024 #endif
00025 
00026 FREECLOTH_NAMESPACE_START
00027 
00028 ////////////////////////////////////////////////////////////////////////////////
00029 // FORWARD DECLARATIONS
00030 
00031 class GePoint;
00032 
00033 ////////////////////////////////////////////////////////////////////////////////
00034 /*!
00035  * \class GeVector freecloth/geom/geVector.h
00036  * \brief A class for 3D vectors.
00037  *
00038  * In keeping with the principles of affine spaces, we distinguish between
00039  * vectors and points, which represent direction and position, respectively.
00040  */
00041 class GeVector {
00042 
00043 public:
00044 
00045     // ----- static member functions -----
00046 
00047     //! Retrieve vector for x,y,z axis given 0,1,2.
00048     static const GeVector& axis( UInt32 idx );
00049 
00050     // ----- member functions -----
00051     GeVector();
00052     GeVector( Float x, Float y, Float z );
00053     //! Construct a vector from p2-p1
00054     GeVector( const GePoint& p1, const GePoint& p2 );
00055     // Default copy constructor is fine.
00056 
00057     // Default assignment operator is fine.
00058     GeVector& operator+=( const GeVector& );
00059     GeVector& operator-=( const GeVector& );
00060     GeVector& operator+=( Float );
00061     GeVector& operator-=( Float );
00062     GeVector& operator*=( Float );
00063     GeVector& operator/=( Float );
00064     GeVector operator-() const;
00065     GeVector operator+( const GeVector& ) const;
00066     GeVector operator-( const GeVector& ) const;
00067     GeVector operator+( Float ) const;
00068     GeVector operator-( Float ) const;
00069     GeVector operator*( Float ) const;
00070     GeVector operator/( Float ) const;
00071     bool operator==( const GeVector& ) const;
00072     bool operator!=( const GeVector& ) const;
00073     Float operator[]( UInt32 ) const;
00074     Float& operator[]( UInt32 );
00075 
00076     //! Dot product
00077     Float dot( const GeVector& ) const;
00078     //! Cross product
00079     GeVector cross( const GeVector& ) const;
00080 
00081     //! Vector length (L2 norm)
00082     Float length() const;
00083     Float squaredLength() const;
00084     //! max(|x|,|y|,|z|)
00085     Float infinityNorm() const;
00086 
00087     bool isUnit() const;
00088     GeVector getUnit() const;
00089 
00090     // FIXME: this is more of a 2d thing... kill it.
00091     Float getAngle( const GeVector& ) const;
00092 
00093     // ----- static data members -----
00094     static const GeVector ZERO;
00095     static const GeVector X,Y,Z;
00096 
00097     // ----- data members -----
00098     Float _x,_y,_z;
00099 };
00100 
00101 
00102 ////////////////////////////////////////////////////////////////////////////////
00103 // GLOBAL FUNCTIONS
00104 //
00105 std::ostream& operator<<( std::ostream&, const GeVector& );
00106 GeVector operator*( Float, GeVector const& );
00107 
00108 FREECLOTH_NAMESPACE_END
00109 
00110 #include <freecloth/geom/geVector.inline.h>
00111 
00112 #endif

Generated on Wed Apr 23 15:58:46 2003 for Freecloth by doxygen1.3-rc3