VectorN.h

00001 /****************************************************************************
00002  * Copyright 2005 Evan Drumwright
00003  * This library is distributed under the terms of the GNU General Public 
00004  * License (found in COPYING).
00005  ****************************************************************************/
00006 
00007 #ifndef _VECTORN_H
00008 #define _VECTORN_H
00009 
00010 #include <boost/shared_ptr.hpp>
00011 #include <boost/shared_array.hpp>
00012 #include <Physsim/Types.h>
00013 
00014 namespace Physsim {
00015 
00016 class MatrixN;
00017         
00019 class VectorN
00020 {
00021         public:
00022                 VectorN();
00023                 VectorN(unsigned N);
00024                 VectorN(const VectorN& source);
00025                 VectorN(unsigned N, const boost::shared_array<Real> array);
00026                 virtual ~VectorN() {}
00027                 virtual Real dot(const VectorN& v) const { return dot(*this, v); }
00028                 static Real dot(const VectorN& v1, const VectorN& v2);
00029                 void normalize() { operator*=(1.0/norm()); }
00030                 static VectorN normalize(const VectorN& v);
00031                 unsigned size() const { return _len; }
00032                 static Real norm(const VectorN& v);
00033                 Real norm() const { return norm(*this); }
00034                 Real len_sq() const { return dot(*this, *this); }
00035                 static VectorN one(unsigned N);
00036                 boost::shared_ptr<MatrixN> outer_prod(const VectorN& v) const { return outer_prod(*this, v); }
00037                 static boost::shared_ptr<MatrixN> outer_prod(const VectorN& v1, const VectorN& v2);
00038                 void augment(const VectorN& v);
00039                 void resize(unsigned N, bool preserve = false);
00040                 void set_zero();
00041                 void set_one();
00042                 VectorN get_sub_vec(unsigned start_idx, unsigned end_idx) const;
00043                 void set_sub_vec(unsigned start_idx, const VectorN& v);
00044                 static VectorN zero(unsigned n);
00045                 bool is_finite() const;
00046                 void operator=(const VectorN* source);
00047                 virtual void operator=(const VectorN& source) { VectorN::operator=(&source); }
00048                 VectorN operator+(const VectorN& v) const;
00049                 void operator+=(const VectorN& v);
00050                 VectorN operator-(const VectorN& v) const;
00051                 void operator-=(const VectorN& v);
00052                 VectorN operator*(Real scalar) const;
00053                 void operator*=(Real scalar);
00054                 VectorN operator/(Real scalar) const;
00055                 void operator/=(Real scalar) { operator*=(1.0/scalar); }
00056                 VectorN operator-() const { return *this * (-1.0); }
00057                 Real& operator[](const unsigned i) { return _data[i]; }
00058                 Real operator[](const unsigned i) const { return _data[i]; }
00059                 boost::shared_array<Real>& data() { return _data; }
00060                 const boost::shared_array<Real>& data() const { return _data; }
00061                 bool operator<(const VectorN& v) const;
00062                 bool operator==(const VectorN& v) const;
00063                 static bool epsilon_equals(const VectorN& v1, const VectorN& v2, Real epsilon);
00064                 bool epsilon_equals(const VectorN& v, Real epsilon) const;
00065                 
00066         protected:
00067                 boost::shared_array<Real> _data;
00068                 unsigned _len;
00069 };
00070 
00071 inline VectorN operator*(Real scalar, const VectorN& v) { return v * scalar; }
00072 std::ostream& operator<<(std::ostream& out, const VectorN& v);
00073 }
00074 
00075 #endif

Generated on Wed Oct 24 14:54:22 2007 for Physsim by  doxygen 1.5.1