-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplanetsystem.h
More file actions
45 lines (37 loc) · 1.05 KB
/
planetsystem.h
File metadata and controls
45 lines (37 loc) · 1.05 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
#ifndef OSIM1_PLANETSYSTEM_H
#define OSIM1_PLANETSYSTEM_H
#include "object.h"
#define G 6.67408e-11
class planetsystem {
public:
object *objects;
unsigned N;
explicit planetsystem(unsigned n) {
objects = new object[n];
N = n;
}
~planetsystem() {
delete[]objects;
}
planetsystem(const planetsystem &ps) {
N = ps.N;
objects = new object[ps.N];
for (int i = 0; i < ps.N; i++)
objects[i] = ps.objects[i];
}
void move() {
cvector f;
for (int i = 0; i < N; i++)
objects[i].f = cvector(0., 0.);
for (int i = 0; i < N; i++) {
for (int x = i + 1; x < N; x++) {
f = ((-G * (objects[i].m * objects[x].m)) / (pow(abs(objects[i].r - objects[x].r), 3))) *
(objects[i].r - objects[x].r);
objects[i].f += -f;
objects[x].f += f;
}
objects[i].move();
}
}
};
#endif //OSIM1_PLANETSYSTEM_H