-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector.cpp
More file actions
72 lines (59 loc) · 1.25 KB
/
Copy pathVector.cpp
File metadata and controls
72 lines (59 loc) · 1.25 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "Vector.h"
Vector::Vector(){
this->x = 0;
this->y = 0;
this->z = 0;
};
Vector::Vector(double x,double y,double z){
this->x = x;
this->y = y;
this->z = z;
};
Vector::~Vector(){};
void Vector::setDirection(double theta,double phi){
aux = getAbs();
x = sind(theta)*sind(phi);
y = cosd(theta)*sind(phi);
z = cosd(phi);
setAbs(aux);
};
void Vector::setPolar(double theta,double phi,double mod){
x = mod*sind(theta)*sind(phi);
y = mod*cosd(theta)*sind(phi);
z = mod*cosd(phi);
};
void Vector::setRect(double x,double y,double z){
this->x = x;
this->y = y;
this->z = z;
};
void Vector::increment(Vector inc){
x += inc.x;
y += inc.y;
z += inc.z;
};
double Vector::getAbs(){
return sqrt(pow(x,2)+pow(y,2)+pow(z,2));
};
void Vector::setAbs(double val){
aux = getAbs();
x *= val/aux;
y *= val/aux;
z *= val/aux;
};
void Vector::mult(double val){
x *= val;
y *= val;
z *= val;
};
void Vector::randomize(double val){
x += val*getAbs()*((double)rand()/RAND_MAX-0.5);
y += val*getAbs()*((double)rand()/RAND_MAX-0.5);
z += val*getAbs()*((double)rand()/RAND_MAX-0.5);
};
double Vector::cosd(double ang){
return cos(PI*ang/180);
}
double Vector::sind(double ang){
return sin(PI*ang/180);
}