#ifndef _MAT_H_ #define _MAT_H_ #include #include #include "Vec.h" /** * @addtogroup math * @{ * @author Philipp Schoenberger * @version 2.0 * * @section LICENSE * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details at * https://www.gnu.org/copyleft/gpl.html * * @section DESCRIPTION * * This file contains the Trajectory for a linear trajectory * The linear trajectory only uses the max speed and ignores * the acceleration parameter. * The movement is a strict hard acceleration and deacceration. * * The slowest joint is defining the speed of the other joints. * By that all joints start and stop the movement synchronously */ template class Vec; template class Mat; // some common vector classes (abbr. names) typedef Mat Mat2f; typedef Mat Mat3f; typedef Mat Mat4f; typedef Mat Mat2d; typedef Mat Mat3d; typedef Mat Mat4d; typedef Mat MatCarthesian; /** * Matrix class for class and simple data types * template with type and size of the vector * * @author Philipp Schoenberger * @copyright 2012 philipp schoenberger All rights reserved. * @license This project is released under the GNU Public License. */ template class Mat { public: /** * standard constructor which is initialising all vales to zero */ Mat () { for (unsigned int x=0; x () { // nothing to do here ... } /** * copy constructor for flat arrays of the simple type * * @param srcData source data for the new matrix */ Mat (const T srcData[SIZE][SIZE]) { for (unsigned int x=0; x (const T initVal,const T eyeVal) { for (unsigned int x=0; x (const T initVal) { for (unsigned int x=0; x (const Mat &srcMat) { for (unsigned int x=0; x=SIZE) y = SIZE-1; if (x>=SIZE) x = SIZE-1; return m_aatData[x][y]; } /** * operator for cell access without writing to it * * @param x x axis position within the matrix * @param y y axis position within the matrix */ T operator () (unsigned x, unsigned y) const { if (x>=SIZE) x = SIZE-1; if (y>=SIZE) y = SIZE-1; return m_aatData[x][y]; } /** * operator to add a simple type to each entry * within the array * * @param scalar the value to add * @return the new calculated matrix */ Mat operator + (const T &scalar) { Mat buf; for (unsigned int x=0; x operator - (const T &scalar) { Mat buf; for (unsigned int x=0; x operator * (const T &scalar) { Mat buf; for (unsigned int row=0; row operator / (const T &scalar) { Mat buf; for (unsigned int row=0; row operator * (const Mat &mat) { Mat buf; for (unsigned int i=0; i &operator = (const T aatData[SIZE*SIZE]) { for (unsigned int row=0; row norm() { T buf; for (unsigned int row=0; row < SIZE; row++) for (unsigned int column=0; column < SIZE; column++) buf += pow(abs(m_aatData[row][column]),2); sqrt(buf); return buf; } /** * This functions generates the transposed matrix for the * current one. * @return the transposed matrix * * @see transpose * @see determinant */ Mat transpose() { Mat buf; for (unsigned int row=0; row inv() { T det = determinant(); if (det== 0) { return *this; } Mat thisTransposed = this->transpose(); thisTransposed/det; return thisTransposed; } /** * This functions copies the vales from the matrix to a flat list * of simple types. The order will be row wise. * @param atData the flat destination array */ void getData (T atData[SIZE*SIZE]) { for (unsigned int row=0; row static std::ostream& operator<< (std::ostream& output,const Mat &mat) { output << "( "; for(unsigned int j =0; j< SIZE; ++j) { output << "( "; for(unsigned int i =0; i< SIZE; ++i) { output << mat(j,i); if (i<4-1) output << " , "; else output << " )"; } if (j getRotationMatrix(float x_angle,float y_angle, float z_angle) { Mat tempx,tempy,tempz; // create x rotation float temp_x[4][4] = { { 1, 0, 0, 0}, { 0, cos(x_angle), -sin(x_angle), 0}, { 0, sin(x_angle), cos(x_angle), 0}, { 0, 0, 0, 1} }; // create y rotation float temp_y[4][4] = { { cos(y_angle), 0, -sin(y_angle), 0}, { 0, 1, 0, 0}, { sin(y_angle), 0, cos(y_angle), 0}, { 0, 0, 0, 1} }; // create z rotation float temp_z[4][4] = { { cos(z_angle), -sin(z_angle), 0, 0}, { sin(z_angle), cos(z_angle), 0, 0}, { 0, 0, 1, 0}, { 0, 0, 0, 1} }; // combine all rotations to a matrix class tempx=temp_x; tempy=temp_y; tempz=temp_z; return tempz*tempy*tempx; } /** * @} */ #endif