Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
position.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __POSITION_H
25 #define __POSITION_H
26 
27 #include <iostream>
28 #include <cmath>
29 
30 class Position
31 {
32 public:
33  Position(){x=y=z=0; array[0]=array[1]=array[2]=0;}
34  Position(double _x, double _y, double _z){ x=_x; y=_y; z=_z; }
35  /// p MUST have a size of at least 3
36  Position(const double* p){ x=p[0]; y=p[1]; z=p[2]; }
37  const double* toArray(){ array[0]=x;array[1]=y; array[2]=z; return array; }
38  Position operator+(const Position& sum) const
39  { Position rv(x+sum.x, y+sum.y, z+sum.z); return rv; }
40  Position operator-(const Position& sum) const
41  { Position rv(x-sum.x, y-sum.y, z-sum.z); return rv; }
42  Position operator*(double f) const { Position rv(x*f, y*f, z*f); return rv; }
43 
44  double length() { return sqrt(x*x+y*y+z*z); }
45 
46  double x;
47  double y;
48  double z;
49 
50  void print(){
51  std::cout << '(' << x << ',' << y << ',' << z << ')' << std::endl;
52  }
53 
54 private:
55  double array[3];
56 };
57 
58 #endif
double x
Definition: position.h:46
Position operator-(const Position &sum) const
Definition: position.h:40
Definition: position.h:30
double y
Definition: position.h:47
Position(const double *p)
p MUST have a size of at least 3
Definition: position.h:36
void print()
Definition: position.h:50
Position()
Definition: position.h:33
Position(double _x, double _y, double _z)
Definition: position.h:34
Position operator*(double f) const
Definition: position.h:42
const double * toArray()
Definition: position.h:37
Position operator+(const Position &sum) const
Definition: position.h:38
double length()
Definition: position.h:44
double z
Definition: position.h:48