How to get the coordinates of vertex of a geometry after rotated?

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…

Hello,

I’m not really sure what you are trying to accomplish. Can you please give a little more detail? Like why are you using a transform?

Best,

Hannah

Hi Hannah,

Thank you for thr reply.

I was trying to use a transformation matrix to cumput the new coordinats after rotating one vertex based on a specific heading, pitch and roll. So I use the transform fuction to make this matrix. But it seems not right.

If I want to comput the coordinats of vertexes of a rotated polygone based on heading, pitch and roll, how to make the transformation matrix? Or any other function can do it.

Many thanks,
Wei

Or I can use entity.orination to rotate polygone, but how to get the rotated coordinates of the polygon from entity.