00001 /************************************************************************************************** 00002 Software License Agreement (BSD License) 00003 00004 Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt 00005 All rights reserved. 00006 00007 Redistribution and use in source and binary forms, with or without modification, are permitted 00008 provided that the following conditions are met: 00009 00010 *Redistributions of source code must retain the above copyright notice, this list of 00011 conditions and the following disclaimer. 00012 *Redistributions in binary form must reproduce the above copyright notice, this list of 00013 conditions and the following disclaimer in the documentation and/or other materials provided 00014 with the distribution. 00015 *Neither the name of the University of Aveiro nor the names of its contributors may be used to 00016 endorse or promote products derived from this software without specific prior written permission. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 00019 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00020 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00021 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00024 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00025 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 ***************************************************************************************************/ 00027 /* 00028 J. Neira 00029 J. A. Castellanos 00030 Robotics and Real Time Group 00031 University of Zaragoza 00032 00033 sp_matrix.h 00034 Implements basic MATRIX operations 00035 */ 00036 /* 00037 * This program is free software; you can redistribute it and/or modify 00038 * it under the terms of the GNU General Public License as published by 00039 * the Free Software Foundation; either version 2 of the License, or 00040 * (at your option) any later version. 00041 * 00042 * This program is distributed in the hope that it will be useful, 00043 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00044 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00045 * GNU General Public License for more details. 00046 * 00047 * You should have received a copy of the GNU General Public License 00048 * along with this program; if not, write to the Free Software 00049 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00050 * 00051 */ 00052 00058 #ifndef _SP_MATRIX_H 00059 #define _SP_MATRIX_H 00060 00061 #ifdef __cplusplus 00062 extern "C" { 00063 #endif 00064 00065 #define MAX_ROWS (7) 00066 #define MAX_COLS (7) 00067 00068 typedef struct { 00069 int rows; 00070 int cols; 00071 float data[MAX_ROWS][MAX_COLS]; 00072 } MATRIX; 00073 00074 typedef struct { 00075 int elements; 00076 float data[MAX_ROWS]; 00077 } VECTOR; 00078 00079 #define DOF (3) 00080 00081 typedef struct { 00082 int mat[DOF]; 00083 int range; 00084 } BMAT; 00085 00086 #define MROWS(m) ((m).rows) 00087 #define MCOLS(m) ((m).cols) 00088 #define MDATA(m,i,j) ((m).data[i][j]) 00089 00090 #define VELEMENTS(v) ((v).elements) 00091 #define VDATA(v,i) ((v).data[i]) 00092 00093 #define M_SQUARE(m) ((m).rows == (m).cols) 00094 #define M_COMPAT_DIM(m, n) ((m).cols == (n).rows) 00095 #define M_EQUAL_DIM(m, n) (((m).rows == (n).rows) && ((m).cols == (n).cols)) 00096 #define V_EQUAL_DIM(v, w) (((v).elements == (w).elements)) 00097 #define MV_COMPAT_DIM(m, v) ((m).cols == (v).elements) 00098 00099 #define FIRST(b) ((b).mat[0]) 00100 #define SECOND(b) ((b).mat[1]) 00101 #define THIRD(b) ((b).mat[2]) 00102 #define RANGE(b) ((b).range) 00103 00104 #define SQUARE(x) ((x)*(x)) 00105 00106 MATRIX create_matrix (int rows, int cols); 00107 void initialize_matrix (MATRIX *m, int rows, int cols); 00108 void diagonal_matrix (MATRIX *m, int dim, float el1, float el2, float el3); 00109 void print_matrix (char *message, MATRIX const *m); 00110 VECTOR create_vector (int elements); 00111 void initialize_vector (VECTOR *v, int elements); 00112 void print_vector (char *message, VECTOR const *v); 00113 float cross_product (MATRIX const *m, int f1, int c1, int f2, int c2); 00114 int determinant (MATRIX const *m, float *result); 00115 int inverse_matrix (MATRIX const *m, MATRIX *n); 00116 int multiply_matrix_vector (MATRIX const *m, VECTOR const *v, VECTOR *r); 00117 00118 #ifdef __cplusplus 00119 } 00120 #endif 00121 00122 #endif 00123