position.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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