-
Notifications
You must be signed in to change notification settings - Fork 1
/
Particle.h
90 lines (70 loc) · 1.98 KB
/
Particle.h
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Particle.h
*
* Created on: 17/03/2016
* Author: Eduardo Gutiérrez
*
* A particle is an infinitelly small point mass. In this workpackage, a particle has the following
attributes (in forthcoming workpackages additional attributes will be needed):
• Mass (real number)
• Position (a vector)
• Velocity (a vector)
It should provide methods for:
• Set and get its mass, position and velocity.
• Integrate
The integrate method updates the particle position given its previous position, velocity and the
ellapsed time (provided as a parameter). The physics laws state that a particle (with constant
velocity) position has to be updated by means of the following equation,
Position2 = Position1 + Velocity * time
With 'time' being a real number representing the ellapsed time in seconds.
*/
#ifndef PARTICLE_H_
#define PARTICLE_H_
#include <math.h>
#include "vector3.h"
#define MOVE 1
#define QUIET 2
namespace MyBilliards {
class particle {
protected:
double mass;
vector3 position;
vector3 velocity;
vector3 acceleration;
vector3 forceAccumulator;
int state;
double time_remaining;
public:
particle();
void integrate(double t);
void init_movement(int destination_x,int destination_y,int duration);
void setState(int state);
int getState();
void clearForceAccumulator();
void addForce(vector3 force);
virtual ~particle();
double getMass() const {
return mass;
}
void setMass(double mass) {
if( mass > 0) this->mass = mass;
else cerr << "Valor de masa no válido. No puede ser ni cero ni negativo" << '\n';
}
const vector3& getPosition() const {
return position;
}
void setPosition(const vector3& position) {
this->position = position;
}
void setPosition(const double x, const double y, const double z) {
position.setVector3( x,y,z);
}
const vector3& getVelocity() const {
return velocity;
}
void setVelocity(const double x, const double y, const double z) {
velocity.setVector3( x,y,z);
}
};
}
#endif /* PARTICLE_H_ */