UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

101 lines 4.48 kB
"use strict"; var GCS_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.GCS = void 0; const tslib_1 = require("tslib"); const decorators_1 = require("../../data/decorators"); const Vector3_1 = require("../math/Vector3"); const AngleUnit_1 = require("./AngleUnit"); const Unit_1 = require("./Unit"); /** * Geodetic coordinate system. */ let GCS = GCS_1 = class GCS extends Unit_1.Unit { /** * @deprecated Use GCS.EARTH_RADIUS_MEAN * @returns {number} Mean earth radius */ static get EARTH_RADIUS() { return GCS_1.EARTH_RADIUS_MEAN; } }; exports.GCS = GCS; GCS.EARTH_RADIUS_MEAN = 6371008.7714; GCS.EARTH_EQUATORIAL_RADIUS = 6378137; GCS.EARTH_POLAR_RADIUS = 6356752.3142; GCS.EARTH_ECCENTRICITY = 8.1819190842622e-2; GCS.EPSG4326 = new GCS_1('EPSG:4326', { baseName: 'gcs', aliases: ['WGS84', 'World Geodetic System'], }); GCS.WGS84 = GCS_1.EPSG4326; GCS.ECEF = new GCS_1('ECEF', { baseName: 'gcs', aliases: ['earth-centered, earth-fixed', 'ECR', 'earth centered rotational'], definitions: [ { inputType: Vector3_1.Vector3, outputType: Vector3_1.Vector3, unit: 'EPSG:4326', toUnit: (input) => { /* @see {@link https://gis.stackexchange.com/questions/265909/converting-from-ecef-to-geodetic-coordinates} */ const f = 1.0 / 298.257223563; const a = GCS_1.EARTH_EQUATORIAL_RADIUS; const b = a - f * a; const e = Math.sqrt(Math.pow(a, 2) - Math.pow(b, 2)) / a; const clambda = Math.atan2(input.y, input.x); const p = Math.sqrt(Math.pow(input.x, 2.0) + Math.pow(input.y, 2)); let h_old = 0.0; // First guess with h=0 meters let theta = Math.atan2(input.z, p * (1.0 - Math.pow(e, 2.0))); let cs = Math.cos(theta); let sn = Math.sin(theta); let N = Math.pow(a, 2.0) / Math.sqrt(Math.pow(a * cs, 2.0) + Math.pow(b * sn, 2.0)); let h = p / cs - N; while (Math.abs(h - h_old) > 1.0e-6) { h_old = h; theta = Math.atan2(input.z, p * (1.0 - (Math.pow(e, 2.0) * N) / (N + h))); cs = Math.cos(theta); sn = Math.sin(theta); N = Math.pow(a, 2.0) / Math.sqrt(Math.pow(a * cs, 2.0) + Math.pow(b * sn, 2.0)); h = p / cs - N; } return new Vector3_1.Vector3(AngleUnit_1.AngleUnit.RADIAN.convert(clambda, AngleUnit_1.AngleUnit.DEGREE), AngleUnit_1.AngleUnit.RADIAN.convert(theta, AngleUnit_1.AngleUnit.DEGREE), h); }, fromUnit: (input) => { var _a; const phi = AngleUnit_1.AngleUnit.DEGREE.convert(input.y, AngleUnit_1.AngleUnit.RADIAN); const lambda = AngleUnit_1.AngleUnit.DEGREE.convert(input.x, AngleUnit_1.AngleUnit.RADIAN); const height = (_a = input.z) !== null && _a !== void 0 ? _a : 0; const clat = Math.cos(phi); const slat = Math.sin(phi); const clon = Math.cos(lambda); const slon = Math.sin(lambda); const N = GCS_1.EARTH_EQUATORIAL_RADIUS / Math.sqrt(1.0 - Math.pow(GCS_1.EARTH_ECCENTRICITY, 2) * Math.pow(slat, 2)); return new Vector3_1.Vector3((N + height) * clat * clon, (N + height) * clat * slon, (N * (1 - Math.pow(GCS_1.EARTH_ECCENTRICITY, 2)) + height) * slat); }, }, ], }); GCS.EPSG3857 = new GCS_1('EPSG:3857', { baseName: 'gcs', aliases: ['pseudo mercator', 'web mercator'], definitions: [ { inputType: Vector3_1.Vector3, outputType: Vector3_1.Vector3, unit: 'EPSG:4326', fromUnit: (input) => { return new Vector3_1.Vector3((input.x * 20037508.34) / 180, ((Math.log(Math.tan(((90 + input.y) * Math.PI) / 360)) / (Math.PI / 180)) * 20037508.34) / 180, 0); }, toUnit: (input) => { return new Vector3_1.Vector3((input.x * 180) / 20037508.34, (Math.atan(Math.exp((input.y * Math.PI) / 20037508.34)) * 360) / Math.PI - 90, input.z); }, }, ], }); exports.GCS = GCS = GCS_1 = tslib_1.__decorate([ (0, decorators_1.SerializableObject)() ], GCS); //# sourceMappingURL=GCS.js.map