This commit is contained in:
2026-10-21 19:32:02 -04:00
commit b74d278c8e
96 changed files with 54476 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
var GeodeticCoord = require('./geodetic.js');
module.exports = CartesianCoord;
function CartesianCoord(options){
this.x = options.x;
this.y = options.y;
this.z = options.z;
}
CartesianCoord.prototype.toGeodetic = function(ellipsoid){
var modified_b = this.z < 0 ? -ellipsoid.b : ellipsoid.b;
var x = this.x;
var y = this.y;
var z = this.z;
var r = Math.sqr(x*x + y*y);
var e = (modified_b*z - (ellipsoid.a*ellipsoid.a - modified_b*modified_b)) / (ellipsoid.a*r);
var f = (modified_b*z + (ellipsoid.a*ellipsoid.a - modified_b*modified_b)) / (ellipsoid.a*r);
var p = (4/3) * (e*f+1);
var q = 2 * (e*e + f*f);
var d = p*p*p + q*q;
var v;
if(d > 0) {
v = Math.pow(Math.sqrt(d) - q, 1/3) - Math.pow(Math.sqrt(d) + q, 1/3);
} else {
v = 2 * Math.sqrt(-p) * Math.cos(Math.acos(q / (p * Math.sqrt(-p)) ) / 3);
}
if(v*v < Math.abs(p)) {
v = -(v*v*v + 2*q) / 3*p;
}
var g = (Math.sqrt(e*e + v) + e) / 2;
var t = Math.sqrt(g*g + (f - v*g)/(2*g - e)) - g;
var rlat = Math.atan( (ellipsoid.a*(1 - t*t)) / (2*modified_b*t) );
var zlong = Math.atan2(y, x);
if(zlong < 0) zlong += 2*Math.PI;
var height_above_ellipsoid = (r - ellipsoid.a*t) * Math.cos(rlat) + (z - modified_b) * Math.sin(rlat);
var lambda = zlong * Math.PI/180;
if(lambda > 180) lambda -= 360;
return new GeodeticCoord({
lambda: lambda,
phi: rlat * Math.PI/180,
height_above_ellipsoid: height_above_ellipsoid,
ellipsoid: ellipsoid
});
};
+31
View File
@@ -0,0 +1,31 @@
var SphericalCoord = require('./spherical.js');
var Ellipsoid = require('../ellipsoid.js');
module.exports = GeodeticCoord;
function GeodeticCoord(options){
this.options = options;
this.lambda = options.lambda || options.lon; // longitude
this.phi = options.phi || options.lat; // geodetic latitude
this.height_above_ellipsoid = options.height_above_ellipsoid || 0;
this.ellipsoid = options.ellipsoid || new Ellipsoid();
}
GeodeticCoord.prototype.toSpherical = function() {
var ellipsoid = this.ellipsoid;
var coslat = Math.cos(this.phi*Math.PI/180);
var sinlat = Math.sin(this.phi*Math.PI/180);
var rc = ellipsoid.a / Math.sqrt(1 - ellipsoid.epssq * sinlat * sinlat);
var xp = (rc + this.height_above_ellipsoid) * coslat;
var zp = (rc * (1 - ellipsoid.epssq) + this.height_above_ellipsoid) * sinlat;
var r = Math.sqrt(xp*xp + zp*zp);
return new SphericalCoord({
r: r,
phig: 180/Math.PI*Math.asin(zp / r),
lambda: this.lambda
});
};
GeodeticCoord.prototype.clone = function(){
return new GeodeticCoord(this.options);
};
+5
View File
@@ -0,0 +1,5 @@
module.exports = {
Cartesian: require('./cartesian.js'),
Spherical: require('./spherical.js'),
Geodetic: require('./geodetic.js')
};
+54
View File
@@ -0,0 +1,54 @@
var CartesianCoord = require('./cartesian.js');
var LegendreFunction = require('../legendre.js');
module.exports = SphericalCoord;
function SphericalCoord(options){
this.lambda = options.lambda; // longitude
this.phig = options.phig; // geocentric latitude
this.r = options.r; // distance from center of ellipsoid
}
SphericalCoord.prototype.toCartesian = function(){
var radphi = this.phig * Math.PI/180;
var radlambda = this.lambda * Math.PI/180;
return new CartesianCoord({
x: this.r * cos(radphi) * cos(radlambda),
y: this.r * cos(radphi) * sin(radlambda),
z: this.r * sin(radphi)
});
};
SphericalCoord.prototype.toGeodetic = function(ellipsoid){
return this.toCartesian().toGeodetic(ellipsoid);
};
SphericalCoord.prototype.getHarmonicVariables = function(ellipsoid, n_max){
var m, n;
var cos_lambda = Math.cos(Math.PI/180 * this.lambda);
var sin_lambda = Math.sin(Math.PI/180 * this.lambda);
var cos_mlambda = [1.0, cos_lambda];
var sin_mlambda = [0.0, sin_lambda];
var relative_radius_power = [
(ellipsoid.re/this.r) * (ellipsoid.re/this.r)
];
for(n = 1; n <= n_max; n++){
relative_radius_power[n] = relative_radius_power[n-1] * (ellipsoid.re/this.r);
}
for(m = 2; m <= n_max; m++){
cos_mlambda[m] = cos_mlambda[m-1]*cos_lambda - sin_mlambda[m-1]*sin_lambda;
sin_mlambda[m] = cos_mlambda[m-1]*sin_lambda + sin_mlambda[m-1]*cos_lambda;
}
return {
relative_radius_power: relative_radius_power,
cos_mlambda: cos_mlambda,
sin_mlambda: sin_mlambda
};
};
SphericalCoord.prototype.getLegendreFunction = function(n_max) {
return new LegendreFunction(this, n_max);
};