// Get the polygon from your "entity" var polygon = theEntity.polygon; var hierarchy = polygon.hierarchy._value; // "indices" here defines an array, elements of which defines the indice of a vector // defining one corner of a triangle. Add up the areas of those triangles to get // an approximate area for the polygon var indices = Cesium.PolygonPipeline.triangulate(hierarchy.positions, hierarchy.holes); var area = 0; // In square kilometers for (var i = 0; i < indices.length; i += 3) { var vector1 = hierarchy.positions[indices[i]]; var vector2 = hierarchy.positions[indices[i+1]]; var vector3 = hierarchy.positions[indices[i+2]]; // These vectors define the sides of a parallelogram (double the size of the triangle) var vectorC = Cesium.Cartesian3.subtract(vector2, vector1, new Cesium.Cartesian3()); var vectorD = Cesium.Cartesian3.subtract(vector3, vector1, new Cesium.Cartesian3()); // Area of parallelogram is the cross product of the vectors defining its sides var areaVector = Cesium.Cartesian3.cross(vectorC, vectorD, new Cesium.Cartesian3()); // Area of the triangle is just half the area of the parallelogram, add it to the sum. area += Cesium.Cartesian3.magnitude(areaVector)/2.0; }
let long = -1.2917727072831369, lat = 0.7105749513910979, height = 547.7591871983744; let heading = viewer.camera.heading, pitch = viewer.camera.pitch;
let position = viewer.scene.globe.ellipsoid.cartographicToCartesian(new Cesium.Cartographic(long, lat, 0.5 * height)); let offset = offsetFromHeadingPitchRange(heading, pitch, height * 2.0); let transform = Cesium.Transforms.eastNorthUpToFixedFrame(position); Cesium.Matrix4.multiplyByPoint(transform, offset, position);
functionoffsetFromHeadingPitchRange(heading, pitch, range) { pitch = Cesium.Math.clamp(pitch, -Cesium.Math.PI_OVER_TWO, Cesium.Math.PI_OVER_TWO); heading = Cesium.Math.zeroToTwoPi(heading) - Cesium.Math.PI_OVER_TWO; var pitchQuat = Cesium.Quaternion.fromAxisAngle(Cesium.Cartesian3.UNIT_Y, -pitch); var headingQuat = Cesium.Quaternion.fromAxisAngle(Cesium.Cartesian3.UNIT_Z, -heading); var rotQuat = Cesium.Quaternion.multiply(headingQuat, pitchQuat, headingQuat); var rotMatrix = Cesium.Matrix3.fromQuaternion(rotQuat); var offset = Cesium.Cartesian3.clone(Cesium.Cartesian3.UNIT_X); Cesium.Matrix3.multiplyByVector(rotMatrix, offset, offset); Cesium.Cartesian3.negate(offset, offset); Cesium.Cartesian3.multiplyByScalar(offset, range, offset); return offset; }
//Add button to View Aircraft at a Fixed Angle relative to aircraft Sandcastle.addToolbarButton('View Aircraft Fixed Angle', function () { viewer.trackedEntity = undefined; viewer.clock.onTick.addEventListener(function (clock) {
//get 2 positions close together timewise var CC3 = Cesium.Cartesian3; var position1 = entity.position.getValue(clock.currentTime, new CC3()); var position2 = entity.position.getValue(Cesium.JulianDate.addSeconds(clock.currentTime, 1 / 60, new Cesium.JulianDate()), new CC3());
//velocity in terms of Earth Fixed var Wvelocity = CC3.subtract(position2, position1, new CC3()); CC3.normalize(Wvelocity, Wvelocity); var Wup = new CC3(); var Weast = new CC3(); var Wnorth = new CC3(); Cesium.Ellipsoid.WGS84.geodeticSurfaceNormal(position1, Wup); CC3.cross({ x: 0, y: 0, z: 1 }, Wup, Weast); CC3.cross(Wup, Weast, Wnorth);
//velocity in terms of local ENU var Lvelocity = new CC3(); Lvelocity.x = CC3.dot(Wvelocity, Weast); Lvelocity.y = CC3.dot(Wvelocity, Wnorth); Lvelocity.z = CC3.dot(Wvelocity, Wup);
//angle of travel var Lup = new CC3(0, 0, 1); var Least = new CC3(1, 0, 0); var Lnorth = new CC3(0, 1, 0); var x = CC3.dot(Lvelocity, Least); var y = CC3.dot(Lvelocity, Lnorth); var z = CC3.dot(Lvelocity, Lup); var angle = Math.atan2(x, y);//math: y b4 x, heading: x b4 y var pitch = Math.asin(z);//make sure Lvelocity is unitized
var range = 80; var offset = new Cesium.HeadingPitchRange(angle, pitch, range); viewer.scene.camera.lookAt(entity.position.getValue(clock.currentTime), offset); }); //end event listener }); //end button
orientation : new Cesium.VelocityOrientationProperty(position) 可以得到某点的方向,但 position 需要是 Cesium.SampledProperty 根据时间的采样属性