function NewtonEinstein() { this.Year = 31556925.261; // [s] Tropisches Jahr this.Lj = 9460730472580800.0; // [m] this.c = 299792458.0; // [m/s] this.c2 = this.c * this.c; this.d = 26000.0 * this.Lj; // [m] this.a = 9.81; // [m/s^2] this.TN = 0; // [s] this.TE = 0; // [s] this.TauN = 0; // [s] this.TauE = 0; // [s] this.SN = 0; // [m] this.SE = 0; // [m] this.VN = 0; // [m/s] this.VE = 0; // [m/s] this.AN = 0; // [m/s^2] this.AE = 0; // [m/s^2] this.DTN = 0; this.DTE = 0; this.DSN = 0; this.DSE = 0; this.TimeUnitNum = 0; this.TimeUnit = ''; // 1 = 'Y', 2 = 'M', 3 = 'D', 4 = 'h', 5 = 'm', 6 = 's' this.TimeUnitSingle = ''; this.TimeMult = 1; this.TimeSecPerUnit = 's/Jahre'; this.LengthUnitNum = 0; this.LengthUnit = ''; // 1 = 'LY', 2 = 'LM', 'LD', 'Lh', 'Lm', 'Ls', 'AE', 'pc', 9 = 'km' this.LengthMult = 1; this.LengthMeterPerUnit = 'm/Lj'; this.SpeedUnitNum = 3; // c this.SpeedUnit = ''; this.SpeedMult = 1; this.SpeedFormat = ''; this.SpeedDigit = 0; this.TimeUnits = [ 'Jahre', 'Monate', 'Tage', 'h', 'min', 's' ]; this.TimeUnitsSingle = [ 'Jahr', 'Monat', 'Tag', 'h', 'min', 's' ]; this.TimeMults = [ 31556925.261, // Jahre -> s (365.24219052083 * 1Tg = Tropisches- bzw. Kalenderjahr) 2629743.77175, // Mon -> s (Jahre/12) 86400, // Tg -> s (24 * 60 * 60s) 3600, // h -> s (60 * 60s) 60, // min -> s 1 ]; this.LengthUnits = [ 'Lj', 'Lmon', 'Ltg', 'Lh', 'Lmin', 'Ls', 'AE', 'pc', 'km' ]; this.LengthMults = [ 9460730472580800, // Lj -> m (Definition nach Wikipedia: 365.25 * 1Lt, julianisches Jahr = 365.25 Tg) 788394206048400, // Lm -> m (Lj / 12) 25902068371200, // Lt -> m (24 * 60 * 60Ls) 1079252848800, // Lh -> m (60 * 60Ls) 17987547480, // Lmin -> m (60Ls) 299792458, // Ls -> m 149597870700, // AE -> m (Wikipedia) 30856775812815000, // pc -> m (Wikipedia, ca. 3.26Lj) 1000 // km -> m ]; this.SpeedUnits = [ 'm/s', 'km/s', 'km/h', 'c' ]; this.SpeedMults = [ 1, // m/s -> m/s 1e3, // km/s -> m/s 1/3.6, // km/h -> m/s 299792458.0 // c -> m/s ]; this.SpeedFormats = [ 'std', 'std', 'std', 'fix0' ]; this.SpeedDigits = [ 12, 12, 12, 15 ]; } NewtonEinstein.prototype.SetUnits = function() { this.TimeUnit = this.TimeUnits[this.TimeUnitNum]; this.TimeUnitSingle = this.TimeUnitsSingle[this.TimeUnitNum]; this.TimeMult = this.TimeMults[this.TimeUnitNum]; this.TimeSecPerUnit = 's/' + this.TimeUnitSingle; this.LengthUnit = this.LengthUnits[this.LengthUnitNum]; this.LengthMult = this.LengthMults[this.LengthUnitNum]; this.LengthMeterPerUnit = 'm/' + this.LengthUnit; this.SpeedUnit = this.SpeedUnits[this.SpeedUnitNum]; this.SpeedMult = this.SpeedMults[this.SpeedUnitNum]; this.SpeedFormat = this.SpeedFormats[this.SpeedUnitNum]; this.SpeedDigit = this.SpeedDigits[this.SpeedUnitNum]; } NewtonEinstein.prototype.Compute = function() { this.SetUnits(); // Newton this.TN = 2.0 * this.NewtonTofS( this.d / 2.0 ); this.TauN = this.TN; this.SN = this.d; this.VN = this.NewtonVofT( this.TN / 2.0 ); this.AN = this.a; this.DTN = 1; this.DSN = 1; // Einstein this.TE = 2.0 * this.EinsteinTEofS( this.d / 2.0 ); this.TauE = 2.0 * this.EinsteinTAUofT( this.TE / 2.0 ); this.SE = 2.0 * this.EinsteinSRofTau( this.TauE / 2.0 ); this.VE = this.EinsteinVofTE( this.TE / 2.0 ); this.AE = this.EinsteinAEofTE( this.TE / 2.0 ); this.DTE = 1.0 / this.EinsteinDeltaTSofTE( this.TE / 2.0 ); this.DSE = this.DTE; } NewtonEinstein.prototype.sinh = function( x ) { return (Math.exp(x) - Math.exp(-x)) / 2; } NewtonEinstein.prototype.asinh = function( x ) { return Math.log( x + Math.sqrt( x * x + 1 ) ); } NewtonEinstein.prototype.lnexp = function( x ) { return Math.log( ( Math.exp( 2.0 * x ) + 1 ) / 2.0 ) - x; } NewtonEinstein.prototype.NewtonTofS = function( s ) { return Math.sqrt( 2.0 * s / this.a ); } NewtonEinstein.prototype.NewtonVofT = function( t ) { return this.a * t; } NewtonEinstein.prototype.EinsteinTEofS = function( s ) { var sacE = s * this.a / this.c2; var x = sacE + 1; var sqrtArgE = x * x - 1; var relErrorE = Math.abs( (((sacE + 1) - 1) - sacE) / sacE ); var sqrtArgN = 2 * sacE; var relDiffNE = Math.abs( (sqrtArgE - sqrtArgN) / sqrtArgN ); if (relDiffNE / 4 < relErrorE) { // small sac -> choose Newton formula var te = Math.sqrt( 2 * s / this.a ); } else { // bigger sac -> choose Einstein formla: // te = (c/a) * sqrt( (a*s/c^2 + 1)^2 - 1 ) te = (this.c / this.a) * Math.sqrt( sqrtArgE ); } return te; } NewtonEinstein.prototype.EinsteinTAUofT = function( te ) { var atc = this.a * te / this.c; if (Math.abs(atc) < 0.1) { // if term 3 of taylor polynom of sinh is out of range, then taylor2 is more precise than asinh // taylor asinh(x) = x - x^3/6 + 3*x^5/40 var atc2 = atc * atc; var atc3 = atc * atc2; var atc5 = atc2 * atc3; var taylor2 = atc - atc3/6; var taylor3 = 3 * atc5 / 40; if (taylor2 + taylor3 == taylor2) { var t = taylor2; } else { var t = this.asinh( atc ); } } else { var t = this.asinh( atc ); } return this.c / this.a * t; } NewtonEinstein.prototype.EinsteinVofTE = function( t ) { return this.EinsteinDeltaTSofTE( t ) * this.a * t; } NewtonEinstein.prototype.EinsteinAEofTE = function( t ) { var atc = this.a * t / this.c; if (Math.abs(atc) < 0.1) { // if term 3 of taylor polynom of f = 1/(x^2 + 1)^(3/2) is out of range, then taylor2 is more precise than f // taylor 1/( x^2 + 1 )^(3/2) = 1 - 3*x^2/2 + 15*x^4/8 - 35*x^6/16 var atc2 = atc * atc; var atc4 = atc2 * atc2; var atc6 = atc2 * atc4; var taylor2 = 1 - 3 * atc2 / 2 + 15 * atc4 / 8; var taylor3 = 35 * atc6 / 16; if (taylor2 + taylor3 == taylor2) { var a = taylor2; } else { var a = 1 / Math.pow( atc * atc + 1, 1.5 ); } } else { var a = 1 / Math.pow( atc * atc + 1, 1.5 ); } a *= this.a; return a; } NewtonEinstein.prototype.EinsteinDeltaTSofTE = function( t ) { var atc = this.a * t / this.c; if (Math.abs(atc) < 0.1) { // if term 3 of taylor polynom of f = 1/sqrt(x^2 + 1) is out of range, then taylor2 is more precise than f // taylor 1/sqrt( x^2 + 1 ) = 1 - x^2/2 + 3*x^4/8 - 5*x^6/16 var atc2 = atc * atc; var atc4 = atc2 * atc2; var atc6 = atc2 * atc4; var taylor2 = 1 - atc2 / 2 + 3 * atc4 / 8; var taylor3 = 5 * atc6 / 16; if (taylor2 + taylor3 == taylor2) { var deltaTS = taylor2; } else { var deltaTS = 1 / Math.sqrt( atc * atc + 1 ); } } else { var deltaTS = 1 / Math.sqrt( atc * atc + 1 ); } return deltaTS; } NewtonEinstein.prototype.EinsteinSRofTau = function( tau ) { var atc = this.a * tau / this.c; if (Math.abs(atc) < 0.1) { // if term 3 of taylor polynom of lnexp(x) is out of range, then taylor2 is more precise than lnexp(x) // taylor ln( (e^2x + 1) / 2 ) - x = x^2/2 - x^4/12 + x^6/45 var atc2 = atc * atc; var atc4 = atc2 * atc2; var atc6 = atc2 * atc4; var taylor2 = atc2/2 - atc4/12; var taylor3 = atc6 / 45; if (taylor2 + taylor3 == taylor2) { var sr = taylor2; } else { var sr = this.lnexp( atc ); } } else { var sr = this.lnexp( atc ); } return (this.c2 / this.a) * sr; }