WaBis

walter.bislins.ch

Source Code: Earth Gravity Calculator

Source Code of the page Earth Gravity Calculator:

#INCLUDE ControlPanel.inc

<style>
#OutputPanel-grel { background-color: #ddf;  }
#OutputPanel-w0, #InputPanel-wCal, #OutputPanel-wh, #OutputPanel-dw { background-color: #fed;  }
#OutputPanel-g0, #OutputPanel-gh, #OutputPanel-dg { background-color: #dfd; }
</style>


<jscript>

var NumOfDigits = 7;

function CModel() {
  // input
  this.lat = 0;       // deg, latitude
  this.long = 0;      // deg, longitude
  this.alt = 0;       // m, altitude
  this.wCal = 100;    // units, weight mass in any mass units

  this.phi = 0;       // rad, latitude (->lat)
  this.lamda = 0;     // rad, longitude

  // output, all values in metric units
  this.grel = 0;      // gh / g0, relative effective acceleration

  this.g0 = 0;        // effective acceleration on ground
  this.g0r = 0;
  this.g0x = 0;
  this.g0y = 0;
  this.g0z = 0;

  this.g0G = 0;       // pure gravitational acceleration on ground
  this.g0Gr = 0;
  this.g0Gx = 0;
  this.g0Gy = 0;
  this.g0Gz = 0;

  this.a0C = 0;       // centrifugal acceleration on ground
  this.a0Cr = 0;
  this.a0Cx = 0;
  this.a0Cy = 0;
  this.a0Cz = 0;

  this.w0 = 0;        // weight of mass at sea level
  this.wh = 0;        // weight of mass at altitude
  this.dw = 0;        // wh - wCal

  this.gh = 0;        // effective acceleration at ac altitude
  this.ghr = 0;
  this.ghx = 0;
  this.ghy = 0;
  this.ghz = 0;

  this.ghG = 0;       // pure gravitational acceleration at ac altitude
  this.ghGr = 0;
  this.ghGx = 0;
  this.ghGy = 0;
  this.ghGz = 0;

  this.ahC = 0;       // centrifugal acceleration at altitude
  this.ahCr = 0;
  this.ahCx = 0;
  this.ahCy = 0;
  this.ahCz = 0;

  this.dg = 0;        // (gh-g0)/g0
  this.dgG = 0;       // ghG - g0G
  this.da = 0;        // ahC - a0C

  this.P0r = 0;       // pos at sea level
  this.P0x = 0;
  this.P0y = 0;
  this.P0z = 0;
  this.Phr = 0;       // pos at altitude
  this.Phx = 0;
  this.Phy = 0;
  this.Phz = 0;
  this.R = 0;         // dist pos at sea level from earth center
  this.Rh = 0;        // dist pos at altitude from earth center

  this.v = 0;         // ac speed wrt geocentric coord sys
  this.vRot0 = 0;     // tangential earth rotation speed at pos at sea level
  this.vRoth = 0;     // tangential earth rotation speed at pos and alt
  this.vEq = 0;       // tangential speed of earth surface at equator
  this.omega = 0;     // = 2 * pi / T [rad/s], rotation speed of earth

  // contstants
  // GM = G * Mass of earth without mass of atmosphere:
  this.G = 6.67408e-11;
  this.M = 5.97236535672e24; // this.GM / this.G;
  this.T = 86164.098903691; // s, https://en.wikipedia.org/wiki/Earth
  this.Ra = 6378137; // m, http://earth-info.nga.mil/GandG/publications/tr8350.2/wgs84fin.pdf
  this.Rb = 6356752.314245; // m, http://earth-info.nga.mil/GandG/publications/tr8350.2/wgs84fin.pdf
  this.ge = 9.7803253359; // m/s^2, http://earth-info.nga.mil/GandG/publications/tr8350.2/wgs84fin.pdf
  this.gp = 9.8321849378; // m/s^2, http://earth-info.nga.mil/GandG/publications/tr8350.2/wgs84fin.pdf
  this.GM = 3.986004418e14; // m^3/s^2, http://earth-info.nga.mil/GandG/publications/tr8350.2/wgs84fin.pdf

  // units
  this.SpeedUnits = [ 'm/s', 'km/h', 'mph' ];
  this.SpeedMults = [ 1, 1/3.6, 0.44704 ];
  this.SpeedUnitIx = 1;
  this.SpeedUnit = 'km/h';
  this.SpeedMult = 1/3.6;

  this.AltUnits = [ 'm', 'ft', 'FL' ];
  this.AltMults = [ 1, 0.3048, 30.48 ];
  this.AltUnitIx = 0;
  this.AltUnit = 'm';
  this.AltMult = 1;

  this.LenUnits = [ 'm', 'km', 'mi' ];
  this.LenMults = [ 1, 1000, 1609.344 ];
  this.LenUnitIx = 1;
  this.LenUnit = 'km';
  this.LenMult = 1000;
}

CModel.prototype.Reset = function() {
  this.lat = 0; // deg
  this.long = 0; // deg
  this.alt = 0; // m
  this.calAlt = 0;
  this.wCal = 100; // kg
}

CModel.prototype.Update = function() {
  // functions
  var sin = Math.sin;
  var cos = Math.cos;
  var sqrt = Math.sqrt;
  function sqr( x ) { return x * x; }
  function len( x, y ) { return sqrt( sqr(x) + sqr(y) ); }
  function rad( a ) { return a * Math.PI / 180; }
  function sp( x1, y1, x2, y2 ) { return x1 * x2 + y1 * y2; } // scalar product

  // setup units
  this.SpeedUnit = this.SpeedUnits[this.SpeedUnitIx];
  this.SpeedMult = this.SpeedMults[this.SpeedUnitIx]
  this.AltUnit = this.AltUnits[this.AltUnitIx];
  this.AltMult = this.AltMults[this.AltUnitIx];
  this.LenUnit = this.LenUnits[this.LenUnitIx];
  this.LenMult = this.LenMults[this.LenUnitIx];

  // limit inputs
  if (this.lat < -90) this.lat = -90;
  if (this.lat > 90) this.lat = 90;
  if (this.alt < 0) this.alt = 0;
  if (this.alt > 1000000) this.alt = 1000000;
  if (this.wCal < 0) this.wCal = 0;

  // angles in radian, omega, GM
  this.phi = rad( this.lat );
  this.lambda = rad( this.long );
  if (this.T == 0) {
    this.omega = 0;
  } else {
    this.omega = 2 * Math.PI / this.T;
  }

  var a = this.Ra;
  var b = this.Rb;
  var cosp = cos( this.phi );
  var sinp = sin( this.phi );
  var cosl = cos( this.lambda );
  var sinl = sin( this.lambda );
  var cosp2 = sqr( cosp );
  var sinp2 = sqr( sinp );
  var a2 = sqr( a );
  var b2 = sqr( b );

  // positions
  var eps = sqrt( a2 - b2 ) / a;
  var Nphi = a / sqrt(1 - sqr(eps * sinp));
  this.P0r = Nphi * cosp;
  this.P0x = this.P0r * cosl;
  this.P0y = this.P0r * sinl;
  this.P0z = Nphi * (1 - sqr(eps)) * sinp;
  this.Phr = (Nphi + this.alt) * cosp;
  this.Phx = this.Phr * cosl;
  this.Phy = this.Phr * sinl;
  this.Phz = (Nphi * (1 - sqr(eps)) + this.alt) * sinp;
  this.R = len( this.P0r, this.P0z );
  this.Rh = len( this.Phr, this.Phz );

  // earth accelerations
  this.a0Cr = sqr(this.omega) * this.P0r;
  this.a0Cx = this.a0Cr * cosl;
  this.a0Cy = this.a0Cr * sinl;
  this.a0Cz = 0;
  this.a0C  = len( this.a0Cr, this.a0Cz );

  this.g0 = ( a * this.ge * cosp2 + b * this.gp * sinp2 ) / sqrt( a2 * cosp2 + b2 * sinp2 );
  this.g0r = - this.g0 * cosp;
  this.g0x = this.g0r * cosl;
  this.g0y = this.g0r * sinl;
  this.g0z = - this.g0 * sinp;

  this.g0Gr = this.g0r - this.a0Cr;
  this.g0Gx = this.g0x - this.a0Cx;
  this.g0Gy = this.g0y - this.a0Cy;
  this.g0Gz = this.g0z - this.a0Cz;
  this.g0G = len( this.g0Gr, this.g0Gz );

  // rotation speeds
  this.vEq = this.omega * a;
  this.vRot0 = this.omega * this.P0r;
  this.vRoth = this.omega * this.Phr;

  // accelerations at altiitude
  this.ahC = sqr(this.omega) * this.Phr;
  this.ahCr = this.ahC;
  this.ahCx = this.ahCr * cosl;
  this.ahCy = this.ahCr * sinl;
  this.ahCz = 0;

  var f = (a - b) / a;
  var m = sqr(this.omega * a) * b / this.GM;

  this.gh = this.g0 * ( 1 - (2 / a) * ( 1 + f + m - 2 * f * sinp2 ) * this.alt + (3 / a2) * sqr(this.alt) );
  this.ghr = - this.gh * cosp;
  this.ghx =   this.ghr * cosl;
  this.ghy =   this.ghr * sinl;
  this.ghz = - this.gh * sinp;

  this.ghGr = this.ghr - this.ahCr;
  this.ghGx = this.ghx - this.ahCx;
  this.ghGy = this.ghy - this.ahCy;
  this.ghGz = this.ghz - this.ahCz;
  this.ghG  = len( this.ghGr, this.ghGz );

  this.dg = this.gh - this.g0;
  this.dgG = this.ghG - this.g0G;
  this.da = this.ahC - this.a0C;

  // relative acceleration
  this.grel = (this.gh - this.g0) / this.g0;

  // weights
  this.w0 = this.wCal;
  this.wh = this.w0 * (this.gh / this.g0);
  this.dw = this.wh - this.wCal;

}

var Model = new CModel();

function UpdateAll() {
  Model.Update();
  ControlPanels.Update();
}

function Reset() {
  Model.Reset();
  UpdateAll();
}


ControlPanels.NewPanel( {
    Name: 'InputPanel',
    ModelRef: 'Model',
    OnModelChange: UpdateAll,
    Format: 'std',
    Digits: NumOfDigits,
    NCols: 2
  }

).AddHeader( {
    Text: 'Position and Test Weight Data',
    ColSpan: 3
  }

).AddHeader( {
    Text: ControlPanels.ResetButtonR()
  }

).AddTextField( {
    Name: 'lat',
    Label: 'Lat',
    Units: '&deg',
    ConvToModelFunc: function(s) { return NumFormatter.DmsStrToNum( s ); },
  }

).AddTextField( {
    Name: 'long',
    Label: 'Long',
    Units: '&deg',
    ConvToModelFunc: function(s) { return NumFormatter.DmsStrToNum( s ); },
  }

).AddTextField( {
    Name: 'alt',
    Label: 'Alt',
    UnitsRef: 'AltUnit',
    MultRef: 'AltMult'
  }

).AddTextField( {
    Name: 'wCal',
    Label: 'Weight',
    Units: 'units',
  }

).Render();


ControlPanels.NewPanel( {
    Name: 'UnitsPanel',
    ModelRef: 'Model',
    OnModelChange: UpdateAll,
    NCols: 3
  }

).AddHeader( {
    Text: 'Units',
    ColSpan: 6
  }

).AddRadiobuttonField( {
    Name: 'SpeedUnitIx',
    ValueType: 'int',
    Label: 'Speed',
    NCols: 3,
    Items: [
      { Name: 'm/s', Value: '0' },
      { Name: 'km/h', Value: '1' },
      { Name: 'mph', Value: '2' }
    ]
  }

).AddRadiobuttonField( {
    Name: 'AltUnitIx',
    ValueType: 'int',
    Label: 'Alt',
    NCols: 3,
    Items: [
      { Name: 'm', Value: '0' },
      { Name: 'ft', Value: '1' },
      { Name: 'FL', Value: '2' }
    ]
  }

).AddRadiobuttonField( {
    Name: 'LenUnitIx',
    ValueType: 'int',
    Label: 'Length',
    NCols: 3,
    Items: [
      { Name: 'm', Value: '0' },
      { Name: 'km', Value: '1' },
      { Name: 'mi', Value: '2' }
    ]
  }

).Render();


ControlPanels.NewPanel( {
    Name: 'OutputPanel',
    ModelRef: 'Model',
    NCols: 3,
    Format: 'std',
    Digits: NumOfDigits,
    ReadOnly: true
  }

).AddHeader( {
    Text: 'Results',
    ColSpan: 6
  }

).AddTextField( {
    Name: 'w0',
    Label: 'W<sub>o</sub>',
    Units: 'units'
  }

).AddTextField( {
    Name: 'wh',
    Label: 'W<sub>h</sub>',
    Units: 'units'
  }

).AddTextField( {
    Name: 'dw',
    Label: 'W<sub>h</sub> - W<sub>cal</sub>',
    Units: 'units'
  }

).AddTextField( {
    Name: 'g0',
    Label: 'g<sub>o</sub>',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'gh',
    Label: 'g<sub>h</sub>',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'dg',
    Label: 'g<sub>h</sub> - g<sub>o</sub>',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'g0G',
    Label: 'g<sub>oG</sub>',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'ghG',
    Label: 'g<sub>hG</sub>',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'dgG',
    Label: 'g<sub>hG</sub> - g<sub>oG</sub>',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'a0C',
    Label: 'a<sub>oC</sub>',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'ahC',
    Label: 'a<sub>hC</sub>',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'da',
    Label: 'a<sub>hC</sub> - a<sub>oC</sub>',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'vRot0',
    Label: 'v<sub>o</sub>',
    UnitsRef: 'SpeedUnit',
    MultRef: 'SpeedMult'
  }

).AddTextField( {
    Name: 'vRoth',
    Label: 'v<sub>h</sub>',
    UnitsRef: 'SpeedUnit',
    MultRef: 'SpeedMult'
  }

).AddTextField( {
    Name: 'vEq',
    Label: 'v<sub>eq</sub>',
    UnitsRef: 'SpeedUnit',
    MultRef: 'SpeedMult'
  }

).AddTextField( {
    Name: 'R',
    Label: 'R<sub>o</sub>',
    UnitsRef: 'LenUnit',
    MultRef: 'LenMult'
  }

).AddTextField( {
    Name: 'Rh',
    Label: 'R<sub>h</sub>',
    UnitsRef: 'LenUnit',
    MultRef: 'LenMult'
  }

).AddTextField( {
    Name: 'grel',
    Label: '(g<sub>h</sub>-g<sub>o</sub>)/g<sub>o</sub>',
    Mult: 0.01,
    Units: '%',
  }

).Render();


ControlPanels.NewPanel( {
    Name: 'VectorsPanel',
    ModelRef: 'Model',
    NCols: 3,
    Format: 'std',
    Digits: NumOfDigits,
    ReadOnly: true
  }

).AddHeader( {
    Text: 'Vector-Results',
    ColSpan: 6
  }

).AddTextField( {
    Name: 'P0x',
    Label: 'P<sub>o</sub>: x',
    UnitsRef: 'LenUnit',
    MultRef: 'LenMult'
  }

).AddTextField( {
    Name: 'P0y',
    Label: 'y',
    UnitsRef: 'LenUnit',
    MultRef: 'LenMult'
  }

).AddTextField( {
    Name: 'P0z',
    Label: 'z',
    UnitsRef: 'LenUnit',
    MultRef: 'LenMult'
  }

).AddTextField( {
    Name: 'Phx',
    Label: 'P<sub>h</sub>: x',
    UnitsRef: 'LenUnit',
    MultRef: 'LenMult'
  }

).AddTextField( {
    Name: 'Phy',
    Label: 'y',
    UnitsRef: 'LenUnit',
    MultRef: 'LenMult'
  }

).AddTextField( {
    Name: 'Phz',
    Label: 'z',
    UnitsRef: 'LenUnit',
    MultRef: 'LenMult'
  }

).AddTextField( {
    Name: 'g0x',
    Label: 'g<sub>o</sub>: x',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'g0y',
    Label: 'y',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'g0z',
    Label: 'z',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'g0Gx',
    Label: 'g<sub>oG</sub>: x',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'g0Gy',
    Label: 'y',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'g0Gz',
    Label: 'z',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'a0Cx',
    Label: 'a<sub>oC</sub>: x',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'a0Cy',
    Label: 'y',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'a0Cz',
    Label: 'z',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'ghx',
    Label: 'g<sub>h</sub>: x',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'ghy',
    Label: 'y',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'ghz',
    Label: 'z',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'ghGx',
    Label: 'g<sub>hG</sub>: x',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'ghGy',
    Label: 'y',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'ghGz',
    Label: 'z',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'ahCx',
    Label: 'a<sub>hC</sub>: x',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'ahCy',
    Label: 'y',
    Units: 'm/s<sup>2</sup>'
  }

).AddTextField( {
    Name: 'ahCz',
    Label: 'z',
    Units: 'm/s<sup>2</sup>'
  }

).Render();


ControlPanels.NewPanel( {
    Name: 'ParameterPanel',
    ModelRef: 'Model',
    OnModelChange: UpdateAll,
    Format: 'std',
    Digits: NumOfDigits,
    NCols: 2,
    ReadOnly: true,
  }

).AddHeader( {
    Text: 'Earth Parameters',
    ColSpan: 4
  }

).AddTextField( {
    Name: 'M',
    Label: 'Mass',
    Units: 'kg'
  }

).AddTextField( {
    Name: 'T',
    Label: 'RotPeriod',
    Units: 'h',
    Mult: 3600,
  }

).AddTextField( {
    Name: 'Ra',
    Label: 'R<sub>eq</sub>',
    Units: 'km',
    Mult: 1000,
  }

).AddTextField( {
    Name: 'Rb',
    Label: 'R<sub>pol</sub>',
    Units: 'km',
    Mult: 1000,
  }

).AddTextField( {
    Name: 'ge',
    Label: 'g<sub>eq</sub>',
    Units: 'm/s<sup>2</sup>',
  }

).AddTextField( {
    Name: 'gp',
    Label: 'g<sub>pol</sub>',
    Units: 'm/s<sup>2</sup>',
  }

).Render();


xOnLoad( UpdateAll );

</jscript>

Weitere Infos zur Seite
Erzeugt Friday, August 31, 2018
von wabis
Zum Seitenanfang
Geändert Sunday, October 6, 2019
von wabis