Robot Simulator of the Robotics Group for Self-Organization of Control: position.h Source File

# position.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
    00003  *    Georg Martius  <georg dot martius at web dot de>                     *
    00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
    00005  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
    00006  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
    00007  *                                                                         *
    00008  *   This program is free software; you can redistribute it and/or modify  *
    00009  *   it under the terms of the GNU General Public License as published by  *
    00010  *   the Free Software Foundation; either version 2 of the License, or     *
    00011  *   (at your option) any later version.                                   *
    00012  *                                                                         *
    00013  *   This program is distributed in the hope that it will be useful,       *
    00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00016  *   GNU General Public License for more details.                          *
    00017  *                                                                         *
    00018  *   You should have received a copy of the GNU General Public License     *
    00019  *   along with this program; if not, write to the                         *
    00020  *   Free Software Foundation, Inc.,                                       *
    00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00022  *                                                                         *
    00023  ***************************************************************************/
    00024 #ifndef __POSITION_H
    00025 #define __POSITION_H
    00026
    00027 #include <iostream>
    00028 #include <cmath>
    00029
    00030 class Position
    00031 {
    00032 public:
    00033   Position(){x=y=z=0; array[0]=array[1]=array[2]=0;}
    00034   Position(double _x, double _y, double _z){ x=_x; y=_y; z=_z; }
    00035   ///  p MUST have a size of at least 3
    00036   Position(const double* p){ x=p[0]; y=p[1]; z=p[2]; }
    00037   const double* toArray(){ array[0]=x;array[1]=y; array[2]=z; return array; }
    00038   Position operator+(const Position& sum) const
    00039            { Position rv(x+sum.x, y+sum.y, z+sum.z); return rv; }
    00040   Position operator-(const Position& sum) const
    00041            { Position rv(x-sum.x, y-sum.y, z-sum.z); return rv; }
    00042   Position operator*(double f) const { Position rv(x*f, y*f, z*f); return rv; }
    00043
    00044   double length() { return sqrt(x*x+y*y+z*z);  }
    00045
    00046   double x;
    00047   double y;
    00048   double z;
    00049
    00050   void print(){
    00051     std::cout << '(' << x << ',' << y << ',' << z << ')' << std::endl;
    00052   }
    00053
    00054 private:
    00055   double array[3];
    00056 };
    00057
    00058 #endif