function fromDegrees(longitude, latitude, height = 0.0) {
longitude = (longitude * Math.PI) / 180.0;
latitude = (latitude * Math.PI) / 180.0;
const radiiSquared = {
x: 6378137.0 * 6378137.0,
y: 6378137.0 * 6378137.0,
z: 6356752.3142451793 * 6356752.3142451793
};
let scratchN = {};
const cosLatitude = Math.cos(latitude);
scratchN.x = cosLatitude * Math.cos(longitude);
scratchN.y = cosLatitude * Math.sin(longitude);
scratchN.z = Math.sin(latitude);
const magnitude = Math.sqrt(
scratchN.x * scratchN.x + scratchN.y * scratchN.y + scratchN.z * scratchN.z
);
scratchN = {
x: scratchN.x / magnitude,
y: scratchN.y / magnitude,
z: scratchN.z / magnitude
};
let scratchK = {
x: radiiSquared.x * scratchN.x,
y: radiiSquared.y * scratchN.y,
z: radiiSquared.z * scratchN.z
};
const gamma = Math.sqrt(
scratchN.x * scratchK.x + scratchN.y * scratchK.y + scratchN.z * scratchK.z
);
scratchK = {
x: scratchK.x / gamma,
y: scratchK.y / gamma,
z: scratchK.z / gamma
};
scratchN = {
x: scratchN.x * height,
y: scratchN.y * height,
z: scratchN.z * height
};
return {
x: scratchK.x + scratchN.x,
y: scratchK.y + scratchN.y,
z: scratchK.z + scratchN.z
};
}
fromDegrees(113.06185677220381, 22.643010101500558, 71.77421163083095);