UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

90 lines 3.52 kB
var GCS_1; import { __decorate } from "tslib"; import { SerializableObject } from '../../data/decorators'; import { Vector3 } from '../math/Vector3'; import { AngleUnit } from './AngleUnit'; import { Unit } from './Unit'; /** * Geodetic coordinate system. */ let GCS = GCS_1 = class GCS extends Unit { /** * @deprecated Use GCS.EARTH_RADIUS_MEAN * @returns {number} Mean earth radius */ static get EARTH_RADIUS() { return GCS_1.EARTH_RADIUS_MEAN; } }; 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, outputType: 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(AngleUnit.RADIAN.convert(clambda, AngleUnit.DEGREE), AngleUnit.RADIAN.convert(theta, AngleUnit.DEGREE), h); }, fromUnit: input => { var _a; const phi = AngleUnit.DEGREE.convert(input.y, AngleUnit.RADIAN); const lambda = AngleUnit.DEGREE.convert(input.x, 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((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, outputType: Vector3, unit: 'EPSG:4326', fromUnit: input => { return new 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(input.x * 180 / 20037508.34, Math.atan(Math.exp(input.y * Math.PI / 20037508.34)) * 360 / Math.PI - 90, input.z); } }] }); GCS = GCS_1 = __decorate([SerializableObject()], GCS); export { GCS };