Skip to content

Commit 07b5f9e

Browse files
committed
add relativity
1 parent 1fd79bf commit 07b5f9e

File tree

13 files changed

+695
-0
lines changed

13 files changed

+695
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
compile:
2+
# Choosing to run compilation tests on 2 different Arduino platforms
3+
platforms:
4+
- uno
5+
- leonardo
6+
- due
7+
- zero
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
name: Arduino-lint
3+
4+
on: [push, pull_request]
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: arduino/arduino-lint-action@v1
11+
with:
12+
library-manager: update
13+
compliance: strict
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
name: Arduino CI
3+
4+
on: [push, pull_request]
5+
6+
jobs:
7+
arduino_ci:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: Arduino-CI/action@master
13+
# Arduino-CI/[email protected]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: json-syntax-check
15+
uses: limitusus/json-syntax-check@v1
16+
with:
17+
pattern: "\\.json$"
18+

libraries/relativity/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021-2021 Rob Tillaart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

libraries/relativity/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2+
[![Arduino CI](https://github.com/RobTillaart/relativity/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
3+
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/relativity/blob/master/LICENSE)
4+
[![GitHub release](https://img.shields.io/github/release/RobTillaart/relativity.svg?maxAge=3600)](https://github.com/RobTillaart/relativity/releases)
5+
6+
7+
# relativity
8+
9+
Arduino library with relativity functions.
10+
11+
12+
## Description
13+
14+
This experimental library implements a number of functions that give indication of the time dilation etc due to relativistic speed.
15+
16+
Goal: Educational purposes or when one puts a cubesat into space :)
17+
18+
19+
## Interface
20+
21+
- **relativity()** constructor
22+
- **double getC()** returns speed of light
23+
- **double getG()** returns gravitational constant
24+
- **double factor(double speed)** returns sqrt(1-v2/c2)
25+
- **double gamma(double speed)** returns 1/sqrt(1-v2/c2)
26+
- **double relativeTime(double time, double speed)** returns the relative time for given time and speed.
27+
- **double relativeLength(double length, double speed)** returns the relative length for given length and speed.
28+
- **double relativeMass(double mass, double speed)** returns the relative mass for given mass and speed.
29+
- **double EnergyMass(double mass, double speed)** returns the energyMass for given mass and speed. Think E = mc^2.
30+
31+
32+
### Caching variants
33+
34+
These functions are the same however the math to calculate a given factor and gamma is done only once and cached. So these function will perform a bit better, especially if floating point is slow.
35+
36+
- **void setSpeed(double speed = 0)** set the speed once and calculate the factor and gamma to minimize math for next functions. Think caching.
37+
- **double getSpeed()** returns speed set.
38+
- **double getFactor()** returns factor for speed set
39+
- **double getGamma()** returns gamma for speed set.
40+
- **double relativeTime(double time)** returns the relative time for speed set with **setSpeed()**.
41+
- **double relativeLength(double length)** returns the relative length for speed set.
42+
- **double relativeMass(double mass)** returns the relative mass for speed set.
43+
- **double EnergyMass(double mass)** returns the energy mass for for speed set.
44+
45+
46+
### Gravity effects
47+
48+
- **double gravitationalTime(double time, double speed)** returns time dilation due to gravitational effects.
49+
- **double diameterEarth(uint8_t longitude = 45)** calculates the diameter of the Earth given it is not a nice circle but more an ellipse, flatter on the poles and thicker on the equator.
50+
Longitude is in (absolute) degrees.
51+
- **double getPlanetMass(uint8_t n)** returns planet mass in kg where 0 = Sun, 1 = Mercury etc
52+
- **double getPlanetRadius(uint8_t n)** returns planet radius in kg where 0 = Sun, 1 = Mercury etc
53+
54+
55+
## Operations
56+
57+
See examples for typical usage.
58+
59+
60+
## Future
61+
62+
- test test test test
63+
- add more functions
64+
- fix some overflow conditions.
65+
66+
- add moons?
67+
- add caching version of mass / radius;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// FILE: gamma_table.ino
3+
// AUTHOR: Rob Tillaart
4+
// VERSION: 0.1.0
5+
// PURPOSE: test formulas
6+
// DATE: 2021-05-29
7+
// URL: https://github.com/RobTillaart/relativity
8+
9+
10+
#include "relativity.h"
11+
12+
13+
uint32_t start, stop;
14+
15+
relativity R;
16+
17+
void setup()
18+
{
19+
Serial.begin(115200);
20+
Serial.println(__FILE__);
21+
22+
Serial.print("\nSpeed of light (m/s):\t");
23+
Serial.println(R.getC());
24+
25+
Serial.println("\n Percentage\t Speed\t\t factor\t\t gamma\n");
26+
27+
for (double perc = 1; perc < 99.9999; perc += (100 - perc) / 10)
28+
{
29+
double v = R.getC() * perc * 0.01;
30+
31+
Serial.print(" ");
32+
Serial.print(perc, 5);
33+
Serial.print("\t ");
34+
Serial.print(v * 0.001);
35+
Serial.print("\t ");
36+
Serial.print(R.factor(v), 6);
37+
Serial.print("\t ");
38+
Serial.print(R.gamma(v ), 6);
39+
Serial.println();
40+
}
41+
Serial.println("done...");
42+
}
43+
44+
45+
void loop()
46+
{
47+
}
48+
49+
// -- END OF FILE --
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// FILE: gravity_demo.ino
3+
// AUTHOR: Rob Tillaart
4+
// VERSION: 0.1.0
5+
// PURPOSE: test formulas
6+
// DATE: 2021-05-29
7+
// URL: https://github.com/RobTillaart/relativity
8+
9+
10+
#include "relativity.h"
11+
12+
relativity R;
13+
14+
15+
void setup()
16+
{
17+
Serial.begin(115200);
18+
Serial.println(__FILE__);
19+
20+
Serial.print("\nSpeed of light (m/s):\t");
21+
Serial.println(R.getC());
22+
23+
for (uint8_t p = 0; p < 4; p++)
24+
{
25+
Serial.print(p);
26+
Serial.print(":\t");
27+
Serial.println(R.gravitationalTime(1, R.getPlanetMass(p), R.getPlanetRadius(p)));
28+
}
29+
30+
Serial.println("\ndone...");
31+
}
32+
33+
34+
void loop()
35+
{
36+
}
37+
38+
// -- END OF FILE --
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//
2+
// FILE: relativity_demo.ino
3+
// AUTHOR: Rob Tillaart
4+
// VERSION: 0.1.0
5+
// PURPOSE: test formulas
6+
// DATE: 2021-05-29
7+
// URL: https://github.com/RobTillaart/relativity
8+
9+
10+
#include "relativity.h"
11+
12+
relativity R;
13+
14+
15+
void setup()
16+
{
17+
Serial.begin(115200);
18+
Serial.println(__FILE__);
19+
20+
Serial.print("\nSpeed of light (m/s):\t");
21+
Serial.println(R.getC());
22+
23+
Serial.println("\n Percentage\t Speed\t\t Time\t\t Length\t\t Mass\n");
24+
25+
for (double perc = 1; perc < 99.9999; perc += (100 - perc) / 10)
26+
{
27+
double v = R.getC() * perc * 0.01;
28+
29+
Serial.print(" ");
30+
Serial.print(perc, 5);
31+
Serial.print("\t ");
32+
Serial.print(v * 0.001);
33+
Serial.print("\t ");
34+
Serial.print(R.relativeTime(1, v), 5);
35+
Serial.print("\t ");
36+
Serial.print(R.relativeLength(1, v ), 5);
37+
Serial.print("\t ");
38+
Serial.print(R.relativeMass(1, v), 3);
39+
Serial.print("\t ");
40+
Serial.print(R.EnergyMass(1, v), 2);
41+
Serial.println();
42+
}
43+
Serial.println("done...");
44+
}
45+
46+
47+
void loop()
48+
{
49+
}
50+
51+
// -- END OF FILE --

libraries/relativity/library.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "relativity",
3+
"keywords": "relativity, speed of light, time, length, mass, dilation",
4+
"description": "library with relativity functions.",
5+
"authors":
6+
[
7+
{
8+
"name": "Rob Tillaart",
9+
"email": "[email protected]",
10+
"maintainer": true
11+
}
12+
],
13+
"repository":
14+
{
15+
"type": "git",
16+
"url": "https://github.com/RobTillaart/relativity.git"
17+
},
18+
"version": "0.1.0",
19+
"license": "MIT",
20+
"frameworks": "*",
21+
"platforms": "*"
22+
}

0 commit comments

Comments
 (0)