Phoenix2D-Library  0.10
Position.cpp
Go to the documentation of this file.
1 /*
2  * Phoenix2D (RoboCup Soccer Simulation 2D League)
3  * Copyright (c) 2013 Ivan Gonzalez
4  *
5  * This file is part of Phoenix2D.
6  *
7  * Phoenix2D is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * Phoenix2D is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Phoenix2D. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "Position.h"
22 #include <cmath>
23 #include "Self.h"
24 #include <sstream>
25 #include <iostream>
26 #include <iomanip>
27 namespace Phoenix
28 {
30  x = 0.0;
31  y = 0.0;
32  theta = 0.0;
33  gamma = 0.0;
34  type = EMPTY_P;
35 }
36 
37 Position::Position(double x, double y) {
38  this->x = x;
39  this->y = y;
40  theta = 0.0;
41  gamma = 0.0;
42  type = POINT_P;
43 }
44 
45 Position::Position(double x, double y, double theta) {
46  this->x = x;
47  this->y = y;
48  this->theta = theta;
49  gamma = 0.0;
50  type = OBJECT;
51 }
52 
53 Position::Position(double x, double y, double theta, double gamma) {
54  this->x = x;
55  this->y = y;
56  this->theta = theta;
57  this->gamma = gamma;
58  type = COMPLETE;
59 }
60 
62 
63 }
64 
65 double Position::getX() {
66  return x;
67 }
68 
69 double Position::getY() {
70  return y;
71 }
72 
74  return theta;
75 }
76 
78  return gamma;
79 }
80 
82  double distance = sqrt(pow(position.getX() - x, 2.0) + pow(position.getY() - y, 2.0));
83  return distance;
84 }
85 
87  double direction = 180.0 * (atan2(position.getY() - y, position.getX() - x)) / Self::PI - (theta + gamma);
88  if (direction >= 180.0) {
89  direction -= 360.0;
90  } else if (direction < -180.0) {
91  direction += 360.0;
92  }
93  return direction;
94 }
95 
97  if (x != 0.0) x *= -1.0;
98  if (y != 0.0) y *= -1.0;
99 }
100 
102  return type;
103 }
104 
105 std::string Position::toString() {
106  std::stringstream ss;
107  //ss << "(" << std::setprecision(4) << x << ", " << y << ", " << theta << ")" << std::endl;
108  ss << "(" << std::setprecision(4) << x << "," << y;
109  switch (type) {
110  case EMPTY_P:
111  break;
112  case POINT_P:
113  break;
114  case OBJECT:
115  ss << "," << std::setprecision(4) << theta;
116  break;
117  case COMPLETE:
118  ss << "," << std::setprecision(4) << theta << "," << gamma;
119  break;
120  default:
121  break;
122  }
123  ss << ")" << std::endl;
124  std::string stringPosition;
125  std::getline(ss, stringPosition);
126  return stringPosition;
127 }
128 }
static double theta
Definition: Self.cpp:91
Position The Position lorem Ipsum
Definition: Position.h:50
static double PI
Definition: Self.h:47
double getBodyDirection()
Definition: Position.cpp:73
static double x
Definition: Self.cpp:89
std::string toString()
Definition: Position.cpp:105
POSITION_TYPE
POSITION_TYPE The Position Type lorem Ipsum
Definition: Position.h:36
double getHeadDirection()
Definition: Position.cpp:77
double getDirectionTo(Position position)
Definition: Position.cpp:86
static double y
Definition: Self.cpp:90
POSITION_TYPE getPositionType()
Definition: Position.cpp:101
POSITION_TYPE type
Definition: Position.h:55
double getDistanceTo(Position position)
Definition: Position.cpp:81
Emtpy.
Definition: Position.h:41