forked from Learning-Python-Team/Particle-Simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFundamentalForces.py
More file actions
46 lines (35 loc) · 1.07 KB
/
Copy pathFundamentalForces.py
File metadata and controls
46 lines (35 loc) · 1.07 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
# Equations used in ParticleSimulator_2D.py
from Settings import *
import math as m
def calculate_gravity(forces_list, a_pos, a_mass, b_pos, b_mass):
bypass = False
if bypass is False:
x_diff = b_pos[0] - a_pos[0]
y_diff = b_pos[1] - a_pos[1]
hypotenuse = m.sqrt((x_diff ** 2) + (y_diff ** 2))
sin = x_diff / hypotenuse
cos = y_diff / hypotenuse
f = (constant_G * a_mass * b_mass) / (hypotenuse ** 2)
forces_list[0] += f * sin
forces_list[1] = f * cos
return forces_list
else:
return forces_list
def calculate_electromagnetic(forces_list, a_pos, b_pos, a_mass, b_mass, a_type, b_type):
fx, fy = forces_list
if a_type or b_type == 'n':
return forces_list
x_diff = b_pos[0] - a_pos[0]
y_diff = b_pos[1] - a_pos[1]
hypotenuse = m.sqrt((x_diff ** 2) + (y_diff ** 2))
sin = x_diff / hypotenuse
cos = y_diff / hypotenuse
f = (constant_coulombs_constant * a_mass * b_mass) / (hypotenuse ** 2)
if a_type == b_type:
fx += (f * sin)
fy -= (f * cos)
else:
fx += (f * sin)
fy += (f * cos)
return forces_list
# def calculate_strong(forces_list, )