Does Cesium have a method to calculate the area of a polygon or shape on the surface of the earth? I know how to do it on a 2D plane, but what about 3D? When a user places a shape on the map (either using polyline or polygon), I want to be able to show the perimeter and area of each shape.
Thanks for your help!
Lydia
--
You received this message because you are subscribed to a topic in the Google Groups "cesium-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cesium-dev/EimmL-poCDI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cesium-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
// 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 polygonvar 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;}