Cesium圆锥体转动跟踪物体函数

2024-12-17  本文已影响0人  aaagu1234
   // position:Cesium.Cartesian3 类型,表示圆锥尖端的位置。
    // az:数字类型,表示圆锥中心线的方位角(水平方向的角度),以弧度为单位。
    // el:数字类型,表示圆锥中心线的仰角(垂直方向的角度),以弧度为单位。
    // range:数字类型,表示圆锥的长度(范围),以米为单位。
    calculateBeam(lng, lat, alt , az, el, range) {
        let position = Cesium.Cartesian3.fromDegrees(lng, lat, alt)
        let heading = Cesium.Math.toRadians(az - 90);
        let pitch = Cesium.Math.toRadians(90 + el) ;
        let hpr = new Cesium.HeadingPitchRoll(heading, pitch, 0.0);
        let x = range/2.0 * Math.sin(pitch) * Math.cos(heading);
        let y = -range/2.0 * Math.sin(heading) * Math.sin(pitch);
        let z = -range/2.0 * Math.cos(pitch);
        var offset = new Cesium.Cartesian3(x, y, z);
        let enuTransform = Cesium.Transforms.eastNorthUpToFixedFrame(position);
        Cesium.Matrix4.multiplyByPointAsVector(enuTransform, offset, offset);
        let newPosition = Cesium.Cartesian3.add(position, offset, new Cesium.Cartesian3());
        let orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);
        return [newPosition, orientation];
    },

这个是正确的函数。
返回一个数组一个是position位置,一个是orientation方位角。
使用entities.add({
position: pos[0],
orientation:pos[1],
})
这个在里面赋值就可以 。

上一篇 下一篇

猜你喜欢

热点阅读