I am trying to calculate the coordinates of each vertex of a polygon. I use Cesium.Transforms.headingPitchRollToFixedFrame() to make the transform matrix and Cesium.Matrix4.multiplyByPoint() to compute the new coordinates.
The following is my code:
var viewer = new Cesium.Viewer(‘cesiumContainer’);
var entities = viewer.entities;
var center = Cesium.Cartesian3.fromDegrees(10, 0);
var heading = Cesium.Math.toRadians(0);
var pitch = Cesium.Math.toRadians(0);
var roll = Cesium.Math.toRadians(0);
var transform = Cesium.Transforms.headingPitchRollToFixedFrame(center, heading, pitch, roll);
entities.add({
polygon: {
hierarchy: new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray([0, 0,
10, 0,
0, 10]))
}
});
var p1 = new Cesium.Cartesian3.fromDegrees(0, 0);
var result1 = Cesium.Matrix4.multiplyByPoint(transform, p1, new Cesium.Cartesian3());
var a1 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(result1);
var p2 = new Cesium.Cartesian3.fromDegrees(10,0);
var result2 = Cesium.Matrix4.multiplyByPoint(transform, p2, new Cesium.Cartesian3());
var a2 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(result2);
var p3 = new Cesium.Cartesian3.fromDegrees(0,10);
var result3 = Cesium.Matrix4.multiplyByPoint(transform, p3, new Cesium.Cartesian3());
var a3 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(result3);
entities.add({
polygon: {
hierarchy: new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray([
Cesium.Math.toDegrees(a1.longitude), Cesium.Math.toDegrees(a1.latitude),
Cesium.Math.toDegrees(a2.longitude), Cesium.Math.toDegrees(a2.latitude),
Cesium.Math.toDegrees(a3.longitude), Cesium.Math.toDegrees(a3.latitude)]))
}
});
viewer.zoomTo(viewer.entities);
But the result shows that the two polygons have distance between and mirror each other even without any rotation…