-
Notifications
You must be signed in to change notification settings - Fork 0
/
Relativistic.lua
88 lines (78 loc) · 2.77 KB
/
Relativistic.lua
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
local Math = require "Math"
local Motion = require "Motion"
local Relativistic = {}
setmetatable(Relativistic, {__index = Relativistic})
-- γ = 1/sqrt(1-v²/c²)
---@param velocity number
---@return number y
function Relativistic:lorentzFactor(velocity)
-- A lower threshold: Increases accuracy but might lead to unnecessary calculations for very low velocities.
-- A higher threshold: Reduces computational cost but might introduce more error for higher velocities.
local beta = velocity / Math.SPEED_OF_LIGHT
local y
if (beta ^ 2) < Motion.lorentzThreshold then
-- Use binomial approximation for low velocities (v << c)
y = 1 + 0.5 * beta ^ 2
else
-- Exact Lorentz factor for relativistic velocities
y = 1 / Math:sqrt(1 - beta ^ 2)
end
return y
end
-- p = γm0v
---@param restMass number
---@param velocity number
---@return number momentum kg.m/s
function Relativistic:momentum(restMass, velocity)
local lorentzFactor = Motion:lorentzFactor(velocity)
local momentum = lorentzFactor * restMass * velocity
return momentum
end
-- E = m0c²
---@param restMass number
---@return number restEnergy J
function Relativistic:restEnergy(restMass)
local restEnergy = restMass * Math.SPEED_OF_LIGHT ^ 2
return restEnergy
end
-- e² = (m0c²)²+(pc)²
-- Approximated as E ≈ m0c² + KE if v << c
-- e² = (m0c²)²+(γm0vc)²
---@param restMass number
---@param velocity number
---@return number totalEnergy J
function Relativistic:totalEnergy(restMass, velocity)
local restEnergy = self:restEnergy(restMass)
local momentum = self:momentum(restMass, velocity)
local kineticEnergy = momentum * Math.SPEED_OF_LIGHT
local totalEnergy = Math:sqrt((restEnergy ^ 2) + (kineticEnergy ^ 2))
return totalEnergy
end
-- e² - (pc)² = (m0c²)²
-- m² = (e² - (pc)²)/c⁴
--- @param energy number
--- @param momentum number
--- @return number restMass kg
function Relativistic:massFromTotalEnergy(energy, momentum)
local restMass = Math:sqrt((energy ^ 2 - (momentum * Math.SPEED_OF_LIGHT) ^ 2) / Math.SPEED_OF_LIGHT ^ 4)
return restMass
end
-- e² - (m0c²)² = (pc)²
-- p² = (e² - (m0c²)²) / c²
---@param energy number
---@param restMass number
---@return number momentum kg.m/s
function Relativistic:momentumFromTotalEnergy(energy, restMass)
local momentum = Math:sqrt((energy ^ 2 - (restMass * Math.SPEED_OF_LIGHT ^ 2) ^ 2) / Math.SPEED_OF_LIGHT ^ 2)
return momentum
end
-- KE = m0c²(γ-1)
---@param restMass number
---@param velocity number
---@return number kineticEnergy J
function Relativistic:kineticEnergy(restMass, velocity)
local lorentz = Motion:lorentzFactor(velocity)
local kineticEnergy = restMass * Math.SPEED_OF_LIGHT ^ 2 * (lorentz - 1)
return kineticEnergy
end
return Relativistic