vue3-Cesium-通过两点确定角度

详细代码

const angle = (p) => {
  let A = Cesium.Cartesian3.fromDegrees(p[0], p[1]);
  let B = Cesium.Cartesian3.fromDegrees(p[3], p[4]);
  let ab = Cesium.Cartesian3.distance(A, B);

  //以a点为原点建立局部坐标系(东方向为x轴,北方向为y轴,垂直于地面为z轴),得到一个局部坐标到世界坐标转换的变换矩阵
  const localToWorld = Cesium.Transforms.eastNorthUpToFixedFrame(
    new Cesium.Cartesian3.fromDegrees(p[0], p[1])
  );
  //求世界坐标到局部坐标的变换矩阵
  const worldToLocal = Cesium.Matrix4.inverse(
    localToWorld,
    new Cesium.Matrix4()
  );
  //A点在局部坐标的位置,其实就是局部坐标原点
  const localPosition_A = Cesium.Matrix4.multiplyByPoint(
    worldToLocal,
    new Cesium.Cartesian3.fromDegrees(p[0], p[1]),
    new Cesium.Cartesian3()
  );
  //B点在以A点为原点的局部的坐标位置
  const localPosition_B = Cesium.Matrix4.multiplyByPoint(
    worldToLocal,
    new Cesium.Cartesian3.fromDegrees(p[3], p[4]),
    new Cesium.Cartesian3()
  );
  //弧度
  const angle = Math.atan2(
    localPosition_B.x - localPosition_A.x,
    localPosition_B.y - localPosition_A.y
  );
  //角度
  let theta = angle * (180 / Math.PI);
  if (theta < 0) {
    theta = theta + 360;
  }
  // console.log([theta, ab]);
  return theta;
};

var p = [116.376385, 39.937953, 1000, 116.429278, 39.578965, 1000]
angle(p)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值