added charges
This commit is contained in:
1 parent
e7cd82c720
commit
09384b878f
2 files changed
+31
No files matched your search
+24
@@ -0,0 +1,24 @@
|
|||||||
|
#include "magnetism.h"
|
||||||
|
#include "consts.h"
|
||||||
|
#include "vec_utils.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#define EPSILON 8.85418782E-12
|
||||||
|
|
||||||
|
void magnetism(universe_t* uni){
|
||||||
|
mass_body_t body_1;
|
||||||
|
mass_body_t body_2;
|
||||||
|
Vector2 diff, force;
|
||||||
|
for (unsigned int i = 0; i < uni->num_bodies-1; i++) {
|
||||||
|
body_1 = uni->bodies[i];
|
||||||
|
for (unsigned int y = i + 1; y < uni->num_bodies; y++) {
|
||||||
|
body_2 = uni->bodies[y];
|
||||||
|
diff=vec2_diff(body_2.position,body_1.position);
|
||||||
|
force = vec2_scale(diff,body_1.charge*body_2.charge/(4*PI*EPSILON*vec2_len(diff)));
|
||||||
|
body_1.speed=vec2_sum(body_1.speed,vec2_scale(force,1/body_1.mass));
|
||||||
|
body_2.speed=vec2_diff(body_2.speed,vec2_scale(force,1/body_2.mass));
|
||||||
|
uni->bodies[y] = body_2;
|
||||||
|
}
|
||||||
|
uni->bodies[i] = body_1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#ifndef MAGNETISM_H
|
||||||
|
#define MAGNETISM_H
|
||||||
|
#include "objects.h"
|
||||||
|
void magnetism(universe_t* univ);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // MAGNETISM_H
|
||||||
Reference in new issue
Block a user