-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVect.cpp
More file actions
50 lines (44 loc) · 946 Bytes
/
Vect.cpp
File metadata and controls
50 lines (44 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* ECE 8853 - Autonomous Control of Robotic Systems
* Project - Tidybot
* Sethu Madhav Bhattiprolu && Arnaud BERNARD
* Spring 2010
*/
#include "Vect.hpp"
Vect::Vect()
{
this->rho = 0;
this->theta = 0;
}
Vect::Vect(double rho, double theta)
{
this->rho = rho;
this->theta = theta;
}
void Vect::norm()
{
while(this->theta > PI)
this->theta -= 2*PI;
while(this->theta <= -PI)
this->theta += 2*PI;
}
Vect::Vect Vect::operator+(const Vect &vect)
{
Vect result;
double resx, resy;
resx = this->rho*cos(this->theta) + vect.rho*cos(vect.theta);
resy = this->rho*sin(this->theta) + vect.rho*sin(vect.theta);
result.rho = sqrt(pow(resx,2)+pow(resy,2));
if(resx == 0 && resy == 0)
result.theta = 0;
else
result.theta = 2*atan(resy/(resx+sqrt(pow(resx,2)+pow(resy,2))));
return result;
}
Vect::Vect Vect::operator*(double factor)
{
Vect result;
result.rho = this->rho*factor;
result.theta = this->theta;
return result;
}