include/vamos/geometry/Three_Matrix.h

Go to the documentation of this file.
00001 //      Vamos Automotive Simulator
00002 //  Copyright (C) 2001--2004 Sam Varner
00003 //
00004 //  This program is free software; you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation; either version 2 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program; if not, write to the Free Software
00016 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 #ifndef _THREE_MATRIX_H_
00019 #define _THREE_MATRIX_H_
00020 
00021 #include "Three_Vector.h"
00022 
00023 namespace Vamos_Geometry
00024 {
00025   // Exception.
00026   class Singular_Matrix {};
00027 
00028   class Three_Matrix
00029   {
00030 public:
00031         double m_mat [3][3];
00032         double m_e_vec [3][3];
00033         double m_e_val [3];
00034   
00035         // The diagonalization routine used by eigen ().
00036         void diagonalize ();
00037 
00038         // Put DIAG in each diagonal element.
00039         void set_diagonal (double diag);
00040 
00041         // Copy the elements of MAT into this matrix.
00042         void copy_in (const Three_Matrix& mat);
00043 
00044         // Default constructor - put DIAG in each diagonal element; set
00045         // other elements to zero.
00046         Three_Matrix (double diag = 0.0);
00047         // Initialize elements with a C-style 2-D array.
00048         Three_Matrix (const double [3][3]);
00049         // Copy constructor.
00050         Three_Matrix (const Three_Matrix& mat);
00051         // Copy assignment.
00052         Three_Matrix& operator = (const Three_Matrix& mat);
00053 
00054         double* operator [] (int index) { return m_mat [index]; }
00055         const double* operator [] (int index) const { return m_mat [index]; }
00056   
00057         // Return the unit vector for a given axis.
00058         Three_Vector unit (int index) const; 
00059 
00060         // Set this matrix to the identity matrix.
00061         void identity ();
00062         // Set all elements to zero.
00063         void zero ();
00064         // Rotate the frame about the vector delta_theta, by an angle equal to
00065         // the magnitude of delta_theta.
00066         void rotate (const Three_Vector& delta_theta);
00067   
00068         // Return the transpose of this matrix.
00069         Three_Matrix transpose () const;
00070 
00071         // Retrun the inverse of this matrix.
00072         Three_Matrix invert () const;
00073 
00074         // Return the eigen vectors of this matrix.  
00075         // Set `e_val' to the eigenvalues.
00076         Three_Matrix eigen (Three_Vector* e_val = 0);
00077 
00078         // Return the product of this matrix and `mat'.
00079         Three_Matrix& operator *= (const Three_Matrix& mat);
00080         Three_Matrix& operator *= (double);
00081   };
00082 
00083   // Multiplication with a matrix.
00084   const Three_Matrix operator * (const Three_Matrix&, const Three_Matrix&);
00085   // Multiplication with a vector.
00086   const inline Three_Vector operator * (const Three_Matrix& mat,
00087                                         const Three_Vector& vec)
00088   {
00089     return Three_Vector 
00090       (vec [0] * mat [0][0] + vec [1] * mat [0][1] + vec [2] * mat [0][2],
00091        vec [0] * mat [1][0] + vec [1] * mat [1][1] + vec [2] * mat [1][2],
00092        vec [0] * mat [2][0] + vec [1] * mat [2][1] + vec [2] * mat [2][2]);
00093   }
00094   const Three_Vector operator * (const Three_Vector&, const Three_Matrix&);
00095   // Multiplication by a scalar.
00096   const Three_Matrix operator * (double, const Three_Matrix&);
00097   const Three_Matrix operator * (const Three_Matrix&, double);
00098 
00099   // Stream operator.
00100   std::ostream& operator << (std::ostream& os, Three_Matrix mat);
00101 
00102   // Return the Euler angles about the x (PHI), y (THETA), and z (PSI)
00103   // axes for the orientation matrix MAT.
00104   void euler_angles (const Three_Matrix& mat, 
00105                                          double* phi, double* theta, double* psi);
00106 }
00107 
00108 #endif

Generated on Thu Oct 19 04:05:48 2006 by  doxygen 1.4.6