美文网首页
Cesium 根据两个坐标点,获取Heading(朝向)

Cesium 根据两个坐标点,获取Heading(朝向)

作者: 懵懵懂懂_YOYO | 来源:发表于2022-12-29 11:06 被阅读0次
    // 计算前一个点位与第二个点位的偏航角
    heading = this.getHeading(Cesium.Cartesian3.fromDegrees(123.0, 30.0), Cesium.Cartesian3.fromDegrees(120.0, 80.0)));
    const pitch = CesiumMath.toRadians(-20.0);
    const range = 50.0;
    this.viewer.camera.lookAt(position, new HeadingPitchRange(heading, pitch, range));
    
    // 根据两个坐标点,获取Heading(朝向)
      getHeading(pointA: Cartesian3, pointB: Cartesian3) {
        //建立以点A为原点,X轴为east,Y轴为north,Z轴朝上的坐标系
        const transform = Transforms.eastNorthUpToFixedFrame(pointA);
        //向量AB
        const positionvector = Cartesian3.subtract(pointB, pointA, new Cartesian3());
        //因transform是将A为原点的eastNorthUp坐标系中的点转换到世界坐标系的矩阵
        //AB为世界坐标中的向量
        //因此将AB向量转换为A原点坐标系中的向量,需乘以transform的逆矩阵。
        const vector = Matrix4.multiplyByPointAsVector(
          Matrix4.inverse(transform, new Matrix4()),
          positionvector,
          new Cartesian3()
        );
        //归一化
        const direction = Cartesian3.normalize(vector, new Cartesian3());
        //heading
        const heading = Math.atan2(direction.y, direction.x) - CesiumMath.PI_OVER_TWO;
        return CesiumMath.TWO_PI - CesiumMath.zeroToTwoPi(heading);
      }
    

    相关文章

      网友评论

          本文标题:Cesium 根据两个坐标点,获取Heading(朝向)

          本文链接:https://www.haomeiwen.com/subject/uoltcdtx.html