special-relativity-time-dilation
·80 words·1 min
special-relativity-time-dilation #
Calculate the time dilation by velocity as described by special relativity using Rust! 🦀
Code #
fn time_dilation_by_velocity(t: f64, v: f64) -> f64 {
t / (1.0 - ((v * v) / (C * C))).sqrt()
}
Units Used #
t: time in seconds
v: km/s
Constants #
const C: f64 = 299_792_458.0;
Equation #
Here is the equation for time dilation from velocity.
See Also #
I also wrote this code in my language called Component seen below: