cesium一些计算函数

设置一条颜色带,由数字0处颜色渐变到1处颜色,计算0-1中插值t处对应的颜色值。

    getColor(t) {
      let material = new Cesium.Color(1.0, 1.0, 1.0, 1.0);//初始化定义material
      return Cesium.Color.lerp(
        Cesium.Color.YELLOW.withAlpha(0.8),//0.0处对应的颜色
        Cesium.Color.RED.withAlpha(0.8),//1.0处对应的颜色
        t,
        material//存储结果的对象
      );
    },

计算两点间距离

    getDistance(start, end) {//start、end为弧度坐标
      var geodesic = new Cesium.EllipsoidGeodesic();
      geodesic.setEndPoints(start, end);
      return geodesic.surfaceDistance;
    },

计算两点连线方向

    //角度 
    getAngle(lng_a, lat_a, lng_b, lat_b) {
      var localToWorld_Matrix = Cesium.Transforms.eastNorthUpToFixedFrame(
        new Cesium.Cartesian3.fromDegrees(lng_a, lat_a)
      );
      var worldToLocal_Matrix = Cesium.Matrix4.inverse(
        localToWorld_Matrix,
        new Cesium.Matrix4()
      );
      var localPosition_A = Cesium.Matrix4.multiplyByPoint(
        worldToLocal_Matrix,
        new Cesium.Cartesian3.fromDegrees(lng_a, lat_a),
        new Cesium.Cartesian3()
      );
      var localPosition_B = Cesium.Matrix4.multiplyByPoint(
        worldToLocal_Matrix,
        new Cesium.Cartesian3.fromDegrees(lng_b, lat_b),
        new Cesium.Cartesian3()
      );
      var angle = Math.atan2(
        localPosition_B.y - localPosition_A.y,
        localPosition_B.x - localPosition_A.x
      );
      var theta = angle * (180 / Math.PI);
      if (theta < 0) {
        theta = theta + 360;
      }
      return 360 - Number(theta.toFixed(0));
    },

    //方向
    setModelDirection(position, angle) {
      let center = position;
      let heading = Cesium.Math.toRadians(angle);
      let pitch = 0;
      let roll = 0;
      let hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
      return Cesium.Transforms.headingPitchRollQuaternion(center, hpr);
    },

给定一个点,延指定角度距离该点定长的另一点坐标

    //点、方向、距离计算另一点
    getPointByDirectionAndLen(position, angle, len) {
      let matrix = Cesium.Transforms.eastNorthUpToFixedFrame(position);
      let mz = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(angle || 0));
      let rotationZ = Cesium.Matrix4.fromRotationTranslation(mz);
      Cesium.Matrix4.multiply(matrix, rotationZ, matrix);
      let result = Cesium.Matrix4.multiplyByPoint(
        matrix,
        new Cesium.Cartesian3(0, len, 0),
        new Cesium.Cartesian3()
      );
      return result;
    },
  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值