Go to Overview over all GrAL packages.
Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Geometry/diag-matrix.h

Go to the documentation of this file.
00001 
00002 // $LICENSE
00003 
00004 #ifndef NMWR_GB_DIAG_MATRIX_NM
00005 #define NMWR_GB_DIAG_MATRIX_NM
00006 
00007 #include "Geometry/matrix.h"
00008 
00009 template<unsigned N>
00010 class diag_matrix : public coordN<N> {
00011   typedef coordN<N> base_vec;
00012 public:
00013   diag_matrix() {}
00014   diag_matrix(component c) : base_vec(c) {}
00015   diag_matrix(const base_vec& rs) : base_vec(rs) {}
00016 
00017   component operator()(unsigned i, unsigned j) const {
00018    return (i == j ? operator[](i) : component(0.0));
00019   }
00020 
00021   diag_matrix<N>& operator*=(const diag_matrix<N>& rs)
00022     { 
00023       for(unsigned i = 1; i <= N; i++)
00024         (*this)[i] *= rs[i];
00025       return *this;
00026     }
00027 
00028   diag_matrix<N>& operator+=(const diag_matrix<N>& rs)
00029     { base_vec::operator+=(rs); return *this;}
00030 
00031   diag_matrix<N>& operator-=(const diag_matrix<N>& rs)
00032     { base_vec::operator-=(rs); return *this;}
00033 
00034   diag_matrix<N>& operator*=(component rs)
00035     { base_vec::operator*=(rs); return *this;}
00036 };
00037 
00038  
00039 template<unsigned N>
00040 inline diag_matrix<N> operator*(const diag_matrix<N>& ls, const diag_matrix<N>& rs)
00041 { diag_matrix<N> tmp(ls); return (tmp *= rs);}
00042 
00043 template<unsigned N>
00044 inline diag_matrix<N> operator+(const diag_matrix<N>& ls, const diag_matrix<N>& rs)
00045 { diag_matrix<N> tmp(ls); return (tmp += rs);}
00046 
00047 template<unsigned N>
00048 inline diag_matrix<N> operator-(const diag_matrix<N>& ls, const diag_matrix<N>& rs)
00049 { diag_matrix<N> tmp(ls); return (tmp -= rs);}
00050 
00051 
00052 template<unsigned N, unsigned M>
00053 void mul(matrix<N,M> & res,
00054          const diag_matrix<M>& D, const matrix<M,N>& A)
00055 {
00056   for(unsigned i = 1; i <= M; i++)
00057     for(unsigned j = 1; j <= N; j++)
00058       res(i,j) = D(i,i) * A(i,j);
00059 }
00060 template<unsigned N, unsigned M>
00061 inline matrix<M,N> operator*(const diag_matrix<M>& D, const matrix<M,N>& A)
00062 {
00063   matrix<M,N> res;
00064   mul(res,D,A);
00065   return res;
00066 }
00067 
00068 
00069 template<unsigned N, unsigned M>
00070 void mul(matrix<N,M> & res,
00071          const matrix<M,N>& A, const diag_matrix<N>& D)
00072 {
00073   for(unsigned int i = 1; i <= M; i++)
00074     for(unsigned int j = 1; j <= N; j++)
00075       res(i,j) = A(i,j) * D(j,j);
00076 }
00077 template<unsigned N, unsigned M>
00078 inline matrix<M,N> operator*(const matrix<M,N>& A,const diag_matrix<N>& D)
00079 {
00080   matrix<M,N> res;
00081   mul(res,A,D);
00082   return res;
00083 }
00084 
00085 
00086 // commutative multiplication of component_type required !!!
00087 template<unsigned N>
00088 inline coordN<N> operator*(const diag_matrix<N>& ls, const coordN<N>& rs)
00089 { diag_matrix<N> tmp(rs); return (tmp*= ls);}
00090 
00091 template<unsigned N>
00092 inline ostream& operator<<(ostream& out, const diag_matrix<N>& rs)
00093 { return (out << coordN<N>(rs)); }
00094 
00095 template<unsigned N>
00096 inline istream& operator>>(istream& in, diag_matrix<N>& rs)
00097 { return (in >> (coordN<N>&)(rs)); }
00098 
00099 #endif

Copyright (c) Guntram Berti 1997-2002. See the GrAL Homepage for up-to-date information.

Generated at Tue Feb 26 15:57:26 2002 for Geometry by doxygen 1.2.11-20011104 written by Dimitri van Heesch, © 1997-2000