-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticle.pde
More file actions
94 lines (75 loc) · 2.09 KB
/
Copy pathParticle.pde
File metadata and controls
94 lines (75 loc) · 2.09 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
public class Particle
{
ParticleType _type;
PVector _s = new PVector(10.0, 10.0, 0.0); // Position (m)
PVector _v = new PVector(0.0, 10.0, 0.0); // Velocity (m/s)
PVector _a; // Acceleration (m/(s*s))
PVector _F; // Force (N)
float _m = 2.0; // Mass (kg)
int _ttl = 100; // Time to live (iterations)
color _color; // Color (RGB)
final static int _particleSize = 7; // Size (pixels)
final static int _casingLength = 10; // Length (pixels)
Particle(ParticleType type, PVector s, PVector v, float m, int ttl, color c)
{
_type = type;
_s = s.copy();
_v = v.copy();
_m = m;
_a = new PVector(0.0 ,0.0, 0.0);
_F = new PVector(0.0, 0.0, 0.0);
_ttl = ttl;
_color = c;
}
void run()
{
update();
display();
}
void update()
{
if (isDead())
return;
updateForce();
// Codigo con la implementación de las ecuaciones diferenciales para actualizar el movimiento de la partícula
_a = PVector.div(_F, _m);
_v.add(PVector.mult(_a, SIM_STEP));
_s.add(PVector.mult(_v, SIM_STEP));
_ttl--;
}
void updateForce()
{
// Código para calcular la fuerza que actua sobre la partícula
PVector Fpeso = PVector.mult(G, _m);
PVector FViento = new PVector();
PVector viento = new PVector();
viento = PVector.sub(_windVelocity, _v);
FViento = PVector.mult(viento, WIND_CONSTANT);
_F = PVector.add(Fpeso, FViento);
}
PVector getPosition()
{
return _s;
}
void display()
{
// Código para dibujar la partícula. Se debe dibujar de forma diferente según si es la carcasa o una partícula normal
switch(_type){
case CASING:
fill(_color);
circle(_s.x, _s.y, _casingLength);
break;
case REGULAR_PARTICLE:
fill(_color);
circle(_s.x, _s.y, _particleSize);
break;
}
}
boolean isDead()
{
if (_ttl < 0)
return true;
else
return false;
}
}