-
Notifications
You must be signed in to change notification settings - Fork 2
/
SpecialRel.py
62 lines (41 loc) · 1.81 KB
/
SpecialRel.py
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
#!/usr/bin/env python
import sys, os, math
c = 299792458
def main():
print("SpecialRel.py has been loaded.")
def ctometer(a): # Converts the speed that is in terms of c to meters per second.
return a * c
def metertoc(a): # Converts the speeed that is in terms of meters per second into terms of c.
return float(a / c)
def gamma(v): # Calculates the gamma taking the speed in terms of c.
return float((1 / math.sqrt((1 - (v**2)))))
def ctogamma(v): # Calculates the value of gamma based on the speed in terms of meters per second.
return float(gamma(metertoc(v)))
def xlorentz(speed, x, t): # Calculates the lorentz transformation for space.
return float(gamma(speed) * (x - speed * t))
def tlorentz(speed, x, t): # Calculates the lorentz transformation for time.
return float(gamma(speed) * (t - speed * x))
def vlorentz(v, w): # Calculates the lorentz transformation for velocity.
return float((v - w) / (1 - (v * w)))
def timedialation(v, t): # Calculates the time dialation based on the velocity and time.
return float(gamma(v) * t)
def lengthcontraction(v, h): # Calculates the length contraction based on the velocity and time.
return float(h / (gamma(v)))
def spacetimeinterval(x, t): # Calculates the spacetime interval based on the space and time.
return float(math.sqrt((t**2) -(x**2)))
def spacetimeinterval2(t1, t2, x1, x2):
return float(math.sqrt((t2 - t1)**2 - (x2 - x1)**2))
def spaceinterval(x1, x2):
return float(x2 - x1)
def timeinterval(t1, t2):
return float(t2 - t1)
def restenergy(m, c):
return float(m * c * c)
def totalenergy(m, v):
gamma_factor = gamma(v)
return float(gamma_factor * m * 3e16)
def totalmomentum(m, v):
gamma_factor = gamma(v)
return float(gamma_factor * m * v)
if __name__=="__main__":
main()