Phoenix2D-Library  0.10
Vector2D.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 "Vector2D.h"
22 #include <cmath>
23 #include "Self.h"
24 #include <sstream>
25 #include <iostream>
26 #include <iomanip>
27 namespace Phoenix
28 {
30  dx = 0.0;
31  dy = 0.0;
32  magnitude = 0.0;
33  direction = 0.0;
34  type = EMPTY_V;
35 }
36 
37 Vector2D::Vector2D(double x, double y) {
38  dx = x;
39  dy = y;
40  magnitude = sqrt(pow(dx, 2.0) + pow(dy, 2.0));
41  direction = 180.0 * atan2(dy, dx) / Self::PI;
42  type = V2D;
43 }
44 
46 
47 }
48 
50  return Vector2D();
51 }
52 
53 Vector2D Vector2D::getVector2DWithMagnitudeAndDirection(double magnitude, double direction) {
54  double x = magnitude * cos(Self::PI * direction / 180.0);
55  double y = magnitude * sin(Self::PI * direction / 180.0);
56  return Vector2D(x, y);
57 }
58 
60  return Vector2D(x, y);
61 }
62 
64  return dx;
65 }
66 
68  return dy;
69 }
70 
72  return magnitude;
73 }
74 
76  return direction;
77 }
78 
80  double x = dx + vector.dx;
81  double y = dy + vector.dy;
82  return Vector2D(x, y);
83 }
84 
86  double x = scalar * magnitude * cos(Self::PI * direction / 180.0);
87  double y = scalar * magnitude * sin(Self::PI * direction / 180.0);
88  return Vector2D(x, y);
89 }
90 
91 std::string Vector2D::toString() {
92  std::stringstream ss;
93  if (type == EMPTY_V) {
94  ss << "(0.0)" << std::endl;
95  } else {
96  ss << "(" << std::setprecision(4) << dx << "," << dy << ")" << std::endl;
97  }
98  std::string stringVelocity;
99  std::getline(ss, stringVelocity);
100  return stringVelocity;
101 }
102 
104  return type;
105 }
106 }
double magnitude
Definition: Vector2D.h:48
Vector 2D.
Definition: Vector2D.h:38
Vector2D operator+(Vector2D vector)
Definition: Vector2D.cpp:79
static double PI
Definition: Self.h:47
double getDirection()
Definition: Vector2D.cpp:75
static Vector2D getVector2DWithXAndY(double dx, double dy)
Definition: Vector2D.cpp:59
double getYComponent()
Definition: Vector2D.cpp:67
static double x
Definition: Self.cpp:89
std::string toString()
Definition: Vector2D.cpp:91
static Vector2D getVector2DWithMagnitudeAndDirection(double magnitude, double direction)
Definition: Vector2D.cpp:53
Vector2D operator*(double scalar)
Definition: Vector2D.cpp:85
static Vector2D getEmptyVector()
Definition: Vector2D.cpp:49
Empty Type.
Definition: Vector2D.h:37
VECTOR_TYPE type
Definition: Vector2D.h:50
VECTOR_TYPE
VECTOR_TYPE The Vector Type lorem Ipsum
Definition: Vector2D.h:36
static double y
Definition: Self.cpp:90
VECTOR_TYPE getType()
Definition: Vector2D.cpp:103
double direction
Definition: Vector2D.h:49
double getXComponent()
Definition: Vector2D.cpp:63
double getMagnitude()
Definition: Vector2D.cpp:71
Vector2D The Vector2D lorem Ipsum
Definition: Vector2D.h:45