00001 //---------------------------------------------------------------------- 00002 // The Motion Strategy Library (MSL) 00003 //---------------------------------------------------------------------- 00004 // 00005 // Copyright (c) University of Illinois and Steven M. LaValle. 00006 // All Rights Reserved. 00007 // 00008 // Permission to use, copy, and distribute this software and its 00009 // documentation is hereby granted free of charge, provided that 00010 // (1) it is not a component of a commercial product, and 00011 // (2) this notice appears in all copies of the software and 00012 // related documentation. 00013 // 00014 // The University of Illinois and the author make no representations 00015 // about the suitability or fitness of this software for any purpose. 00016 // It is provided "as is" without express or implied warranty. 00017 //---------------------------------------------------------------------- 00018 00019 #ifndef MSL_MATRIX_H 00020 #define MSL_MATRIX_H 00021 00022 #include "vector.h" 00023 00024 class MSLMatrix { 00025 00026 MSLVector** v; 00027 int d1; 00028 int d2; 00029 00030 void flip_rows(int,int); 00031 void check_dimensions(const MSLMatrix&) const; 00032 double& elem(int i, int j) const { return v[i]->v[j]; } 00033 double** triang(const MSLMatrix&, int&) const; 00034 00035 public: 00036 00037 MSLMatrix(int n=0, int m=0); 00038 MSLMatrix(int n, int m, double* D); 00039 MSLMatrix(const MSLMatrix&); 00040 MSLMatrix(const MSLVector&); 00041 MSLMatrix& operator=(const MSLMatrix&); 00042 ~MSLMatrix(); 00043 00044 int dim1() const { return d1; } 00045 int dim2() const { return d2; } 00046 MSLVector& row(int i) const; 00047 MSLVector col(int i) const; 00048 MSLMatrix trans() const; 00049 MSLMatrix inv() const; 00050 double det() const; 00051 MSLMatrix solve(const MSLMatrix&) const; 00052 MSLVector solve(const MSLVector& b) const 00053 { return MSLVector(solve(MSLMatrix(b))); } 00054 operator MSLVector() const; 00055 MSLVector& operator[](int i) const { return row(i); } 00056 double& operator()(int i, int j); 00057 double operator()(int,int) const; 00058 int operator==(const MSLMatrix&) const; 00059 int operator!=(const MSLMatrix& x) const { return !(*this == x); } 00060 MSLMatrix operator+(const MSLMatrix& M1) const; 00061 MSLMatrix operator-(const MSLMatrix& M1) const; 00062 MSLMatrix operator-() const; 00063 MSLMatrix& operator-=(const MSLMatrix&); 00064 MSLMatrix& operator+=(const MSLMatrix&); 00065 MSLMatrix operator*(const MSLMatrix& M1) const; 00066 MSLVector operator*(const MSLVector& vec) const 00067 { return MSLVector(*this * MSLMatrix(vec)); } 00068 MSLMatrix operator*(double x) const; 00069 void read(istream& I); 00070 void read() { read(cin); } 00071 00072 friend ostream& operator<<(ostream& O, const MSLMatrix& M); 00073 friend istream& operator>>(istream& I, MSLMatrix& M); 00074 }; 00075 00076 00077 #endif