经纬度坐标转笛卡尔坐标(cesium源码抠出来的)

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);

  

posted @ 2024-07-25 17:52  小韓烟柳  阅读(164)  评论(0)    收藏  举报