首页 > 其他分享 >笛卡尔坐标转经纬度坐标

笛卡尔坐标转经纬度坐标

时间:2024-07-25 17:50:45浏览次数:11  
标签:cartesian const 经纬度 笛卡尔 oneOverRadiiSquared let 坐标 1.0 result

function fromCartesian(cartesian) {
  const oneOverRadii = {
    x: 1.0 / 6378137.0,
    y: 1.0 / 6378137.0,
    z: 1.0 / 6356752.3142451793
  };
  const oneOverRadiiSquared = {
    x: 1.0 / (6378137.0 * 6378137.0),
    y: 1.0 / (6378137.0 * 6378137.0),
    z: 1.0 / (6356752.3142451793 * 6356752.3142451793)
  };

  const p = scaleToGeodeticSurface(
    cartesian,
    oneOverRadii,
    oneOverRadiiSquared,
    0.1
  );

  if (!(p !== undefined && p !== null)) {
    return undefined;
  }

  let n = {
    x: p.x * oneOverRadiiSquared.x,
    y: p.y * oneOverRadiiSquared.y,
    z: p.z * oneOverRadiiSquared.z
  };
  const m1 = magnitude(n);
  n = {
    x: n.x / m1,
    y: n.y / m1,
    z: n.z / m1
  };

  const h = {
    x: cartesian.x - p.x,
    y: cartesian.y - p.y,
    z: cartesian.z - p.z
  };

  const longitude = Math.atan2(n.y, n.x);
  const latitude = Math.asin(n.z);
  const height =
    Math.sign(h.x * cartesian.x + h.y * cartesian.y + h.z * cartesian.z) *
    magnitude(h);

  let result = {};
  result.longitude = (longitude * 180.0) / Math.PI;
  result.latitude = (latitude * 180.0) / Math.PI;
  result.height = height;
  return result;
}

function scaleToGeodeticSurface(
  cartesian,
  oneOverRadii,
  oneOverRadiiSquared,
  centerToleranceSquared
) {
  const positionX = cartesian.x;
  const positionY = cartesian.y;
  const positionZ = cartesian.z;

  const oneOverRadiiX = oneOverRadii.x;
  const oneOverRadiiY = oneOverRadii.y;
  const oneOverRadiiZ = oneOverRadii.z;

  const x2 = positionX * positionX * oneOverRadiiX * oneOverRadiiX;
  const y2 = positionY * positionY * oneOverRadiiY * oneOverRadiiY;
  const z2 = positionZ * positionZ * oneOverRadiiZ * oneOverRadiiZ;

  // Compute the squared ellipsoid norm.
  const squaredNorm = x2 + y2 + z2;
  const ratio = Math.sqrt(1.0 / squaredNorm);

  // As an initial approximation, assume that the radial intersection is the projection point.
  const intersection = {
    x: cartesian.x * ratio,
    y: cartesian.y * ratio,
    z: cartesian.z * ratio
  };

  // If the position is near the center, the iteration will not converge.
  if (squaredNorm < centerToleranceSquared) {
    return !isFinite(ratio) ? undefined : intersection;
  }

  const oneOverRadiiSquaredX = oneOverRadiiSquared.x;
  const oneOverRadiiSquaredY = oneOverRadiiSquared.y;
  const oneOverRadiiSquaredZ = oneOverRadiiSquared.z;

  // Use the gradient at the intersection point in place of the true unit normal.
  // The difference in magnitude will be absorbed in the multiplier.
  const gradient = {
    x: intersection.x * oneOverRadiiSquaredX * 2.0,
    y: intersection.y * oneOverRadiiSquaredY * 2.0,
    z: intersection.z * oneOverRadiiSquaredZ * 2.0
  };

  // Compute the initial guess at the normal vector multiplier, lambda.
  let lambda =
    ((1.0 - ratio) * magnitude(cartesian)) / (0.5 * magnitude(gradient));
  let correction = 0.0;

  let func;
  let denominator;
  let xMultiplier;
  let yMultiplier;
  let zMultiplier;
  let xMultiplier2;
  let yMultiplier2;
  let zMultiplier2;
  let xMultiplier3;
  let yMultiplier3;
  let zMultiplier3;

  do {
    lambda -= correction;

    xMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredX);
    yMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredY);
    zMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredZ);

    xMultiplier2 = xMultiplier * xMultiplier;
    yMultiplier2 = yMultiplier * yMultiplier;
    zMultiplier2 = zMultiplier * zMultiplier;

    xMultiplier3 = xMultiplier2 * xMultiplier;
    yMultiplier3 = yMultiplier2 * yMultiplier;
    zMultiplier3 = zMultiplier2 * zMultiplier;

    func = x2 * xMultiplier2 + y2 * yMultiplier2 + z2 * zMultiplier2 - 1.0;

    // "denominator" here refers to the use of this expression in the velocity and acceleration
    // computations in the sections to follow.
    denominator =
      x2 * xMultiplier3 * oneOverRadiiSquaredX +
      y2 * yMultiplier3 * oneOverRadiiSquaredY +
      z2 * zMultiplier3 * oneOverRadiiSquaredZ;

    const derivative = -2.0 * denominator;

    correction = func / derivative;
  } while (Math.abs(func) > 0.000000000001);

  // if (!(result !== undefined && result !== null)) {
  //   return new Cartesian3(
  //     positionX * xMultiplier,
  //     positionY * yMultiplier,
  //     positionZ * zMultiplier
  //   );
  // }
  let result = {
    x: positionX * xMultiplier,
    y: positionY * yMultiplier,
    z: positionZ * zMultiplier
  };
  return result;
}

function magnitude(cartesian) {
  return Math.sqrt(
    cartesian.x * cartesian.x +
      cartesian.y * cartesian.y +
      cartesian.z * cartesian.z
  );
}

fromCartesian({x:-2307065.8,y:5418833.5,z:2440308.2})

  

标签:cartesian,const,经纬度,笛卡尔,oneOverRadiiSquared,let,坐标,1.0,result
From: https://www.cnblogs.com/xiaohanyanliu/p/18323829

相关文章

  • 经纬度坐标转笛卡尔坐标
    functionfromDegrees(longitude,latitude,height=0.0){longitude=(longitude*Math.PI)/180.0;latitude=(latitude*Math.PI)/180.0;constradiiSquared={x:6378137.0*6378137.0,y:6378137.0*6378137.0,z:6356752.31424517......
  • 地理坐标系与投影坐标系
    ArcGIS中预定义了两套坐标系统,地理坐标系(Geographiccoordinatesystem)和投影坐标系(Projectedcoordinatesystem)1.地理坐标系地理坐标系定义:地理坐标系是以椭球体面为参考面,以法线为依据,用经纬度表示地面点在椭球表面的位置的坐标系统。 简单点来说,地理坐标系是用经纬度来......
  • 带极坐标表达式的水平平均值
    我需要计算极坐标中的行平均值。我在axis的文档中没有看到pl.Expr.mean参数。作为示例,请考虑以下数据框。df=pl.DataFrame({"foo":[1,2,3],"bar":[6,7,8],})如何计算此处的行平均值?谢谢。df.select(pl.mean(["foo","bar"]......
  • 坐标变化其二 前缀和
    202309-2试题名称:坐标变换(其二)时间限制:2.0s内存限制:512.0MB问题描述:问题描述对于平面直角坐标系上的坐标 (......
  • 笛卡尔树
    笛卡尔树:笛卡尔树是关于多个二元组\((k_i,w_i)\)的一棵树,使其所有\(k\)值满足二叉搜索树的性质,且所有\(w\)值都满足小根堆的性质。笛卡尔树有一些关于区间最值的美好性质,常常用于处理关于区间最值的问题。构建方法:在构建时,对于右链上的元素,自底向上一定是\(w\)值由小......
  • 微信小程序 - 最新详细实现集成腾讯地图配置流程及使用教程,基于腾讯位置服务做地图标
    前言网上的教程代码太乱了,并且很少有真实请求的示例,本文提供优质配置教程及示例源码。在微信小程序开发中,详解实现接入腾讯地图教程,后台配置完整流程及使用教程,附带腾讯地图显示渲染和地图标记点,获取本机当前定位省市区或精确的经纬度,IP属地定位获取城市名称/市区名,将经......
  • 创建具有标量特征和 N 维坐标向量特征的机器学习 Numpy 数组
    我正在尝试为ML程序格式化我的数据。有33,000个事件,每个事件有3个我想考虑的东西:质量、能量、坐标。质量的形状为(33000,),看起来像:[188.9189.0125.7...127.4201.0210.1]。能量也是(33000,)并且看起来相同:[123...8910]。然后,我还有一个形状为(33000,......
  • 021集——批量txt格式坐标转dwg——vba代码实现
    在工作中遇到txt转dwg的重复性工作,详细如下:已知若干个txt文件,坐标格式如下:要求:将每个txt格式坐标文件转为dwg,名称与原txt名称一样,即1.txt生成1.dwg。因txt文件中存在一些非坐标文本数字,我们需进行判断只提取xy坐标数据,然后在cad中输入坐标,生成一个轻量线。此项工作只需一......
  • 笛卡尔树
    \(\texttt{0x00}\):前置芝士二叉搜索树堆单调栈\(\texttt{0x01}\):概念笛卡尔树是一种二叉树,每一个结点由一个键值二元组\((k,w)\)构成。要求\(k\)满足二叉搜索树的性质(左小右大),而\(w\)满足堆的性质(大根堆或小根堆)。q1:这么一看,Treap不也是笛卡尔树?a1:正确的。一个有......
  • 用赤道坐标系绘制星图
    我正在尝试使用赤道坐标系(RAJ2000和DEJ2000)生成星图。然而,我只得到一个网格系统,其中经线和平行线是平行的,而纬线应该是弯曲的,经线应该会聚到北天极和南天极。我正在使用一些Python模块:matplotlib、skyfield(用于立体投影)、astroquery(因此我可以瞄准深空中的任何物体)和astr......