0.1.3 relativity

This commit is contained in:
rob tillaart 2022-08-04 12:11:24 +02:00
parent 4d66441771
commit 59f8dd3646
4 changed files with 30 additions and 25 deletions

View File

@ -67,7 +67,11 @@ See examples for typical usage.
## Future ## Future
- test test test test - test test test test
- Split .h into .h and .cpp
- add more functions - add more functions
- Schwarzschild horizon etc
-
- fix some overflow conditions. - fix some overflow conditions.
- add moons? - add moons?
- need a database :)
- add caching version of mass / radius; - add caching version of mass / radius;

View File

@ -15,7 +15,7 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/relativity.git" "url": "https://github.com/RobTillaart/relativity.git"
}, },
"version": "0.1.2", "version": "0.1.3",
"license": "MIT", "license": "MIT",
"frameworks": "*", "frameworks": "*",
"platforms": "*", "platforms": "*",

View File

@ -1,5 +1,5 @@
name=relativity name=relativity
version=0.1.2 version=0.1.3
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=library with relativity functions. sentence=library with relativity functions.

View File

@ -2,7 +2,7 @@
// //
// FILE: relativity.h // FILE: relativity.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.2 // VERSION: 0.1.3
// PURPOSE: Collection relativity formulas // PURPOSE: Collection relativity formulas
// URL: https://github.com/RobTillaart/relativity // URL: https://github.com/RobTillaart/relativity
// //
@ -10,12 +10,13 @@
// 0.1.0 2021-05-29 initial version // 0.1.0 2021-05-29 initial version
// 0.1.1 2021-06-02 fix in tests // 0.1.1 2021-06-02 fix in tests
// 0.1.2 2021-12-27 update library.json, readme, license, minor edits // 0.1.2 2021-12-27 update library.json, readme, license, minor edits
// 0.1.3 2022-08-04 fix constructor
#include "Arduino.h" #include "Arduino.h"
#define RELATIVITY_LIB_VERSION (F("0.1.2")) #define RELATIVITY_LIB_VERSION (F("0.1.3"))
class relativity class relativity
@ -24,9 +25,9 @@ public:
relativity() relativity()
{ {
double _speed = 0.0; _speed = 0.0;
double _factor = 1.0; _factor = 1.0;
double _gamma = 1.0; _gamma = 1.0;
} }
double getC() double getC()
@ -53,7 +54,7 @@ public:
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
// //
// relativistic corrections for speed // relativistic corrections for speed
// //
double relativeTime(double time, double speed) double relativeTime(double time, double speed)
@ -77,12 +78,12 @@ public:
} }
// set speed only once for the 3 values // set speed only once for the 3 values
void setSpeed(double speed = 0) void setSpeed(double speed = 0)
{ {
_speed = speed; _speed = speed;
_factor = factor(speed); _factor = factor(speed);
_gamma = gamma(speed); _gamma = gamma(speed);
} }
double getSpeed() double getSpeed()
@ -113,35 +114,35 @@ public:
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
// //
// relativistic corrections for gravity // relativistic corrections for gravity
// //
double gravitationalTime(double time, double mass, double radius) double gravitationalTime(double time, double mass, double radius)
{ {
// formula tries to stay within float range // formula tries to stay within float range
return time / sqrt(1 - (mass / (radius * _c2)) * (2 * _G) ); return time / sqrt(1 - (mass / (radius * _c2)) * (2 * _G) );
} }
// returns radius in km. // returns radius in km.
double radiusEarth(double longitude = 45) // 0..90 double radiusEarth(double longitude = 45) // 0..90
{ {
// https://www.youtube.com/watch?v=hYMvJum9_Do @ 8:00 // https://www.youtube.com/watch?v=hYMvJum9_Do @ 8:00
// radius polar: 6357 km // radius polar: 6357 km
// radius equator: 6378 km // radius equator: 6378 km
// difference: 21 km // difference: 21 km
double radians = longitude * (PI / 180.0); double radians = longitude * (PI / 180.0);
// approx of the graph in YouTube with a cosine // approx of the graph in YouTube with a cosine
return 6367.5 + 10.5 * cos(radians * 2); return 6367.5 + 10.5 * cos(radians * 2);
} }
// mass in // mass in
double getPlanetMass(uint8_t n) // sun = 0; mercury = 1 etc double getPlanetMass(uint8_t n) // sun = 0; mercury = 1 etc
{ {
return massPlanets[n]; return massPlanets[n];
} }
// radius in km // radius in km
double getPlanetRadius(uint8_t n) // sun = 0; mercury = 1 etc double getPlanetRadius(uint8_t n) // sun = 0; mercury = 1 etc
{ {
return radiusPlanets[n]; return radiusPlanets[n];
@ -156,8 +157,8 @@ private:
const double _G = 6.6742e-11; // gravitational constant const double _G = 6.6742e-11; // gravitational constant
// wikipedia // wikipedia
// kg // kg
const double massPlanets[10] = const double massPlanets[10] =
{ {
1.9891e30, // Sun 1.9891e30, // Sun
@ -172,7 +173,7 @@ private:
13.03e21, // Pluto 13.03e21, // Pluto
}; };
// km // km
const double radiusPlanets[10] = const double radiusPlanets[10] =
{ {
695508, // Sun 695508, // Sun
@ -187,7 +188,7 @@ private:
1188.3, // Pluto 1188.3, // Pluto
}; };
// cache // cache
double _speed = 0.0; double _speed = 0.0;
double _factor = 1.0; double _factor = 1.0;
double _gamma = 1.0; double _gamma = 1.0;