Hi All,

I want to rotate a polygon based on the center point using the value of heading, pitch and roll and get the coordinates of each vertex of the rotated polygon, then use these coordinates to do some other calculations for my application.

I was trying to compute these coordinates by using a transformation matrix to multiply by the the vertexes of the polygon, respectively, before rotated. To create this transformation matrix, I used Cesium.Transforms.headingPitchRollToFixedFrame. However, the result is not what I expected, even without any rotation, the rotated polygon(red) is away from the original one(green) and seems to be rotated by 90 degree.

I tried to used other methods but still have the same problem.

Does anyone can tell me what I am supposed to do?

Many thanks,

Wei

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var entities = viewer.entities;

var center = Cesium.Cartesian3.fromDegrees(5, 2.5);// The center of the polygon

var heading = Cesium.Math.toRadians(30);

var pitch = Cesium.Math.toRadians(0);

var roll = Cesium.Math.toRadians(0);

```
// create the transformation matrix based on a specific value of heading, pitch and roll
```

var rotation = Cesium.Transforms.headingPitchRollToFixedFrame(center, heading, pitch, roll);

```
// add the polygon without any rotation
entities.add({
```

polygon: {

hierarchy: new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray([0, 0,

10, 0,

10, 5,

0, 5])),

material: Cesium.Color.GREEN

}

});

```
// compute the coordinates of each vertex of the rotated polygon
```

var p1 = new Cesium.Cartesian3.fromDegrees(0, 0);

Cesium.Matrix4.multiplyByPoint(rotation,p1,p1);

var a1 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(p1);

var p2 = new Cesium.Cartesian3.fromDegrees(10, 0);

Cesium.Matrix4.multiplyByPoint(rotation,p2,p2);

var a2 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(p2);

var p3 = new Cesium.Cartesian3.fromDegrees(10, 5);

Cesium.Matrix4.multiplyByPoint(rotation,p3,p3);

var a3 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(p3);

var p4 = new Cesium.Cartesian3.fromDegrees(0, 5);

Cesium.Matrix4.multiplyByPoint(rotation,p4,p4);

var a4 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(p4);

// add the rotated polygon

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),

Cesium.Math.toDegrees(a4.longitude), Cesium.Math.toDegrees(a4.latitude)])),

material: Cesium.Color.RED

}

});

viewer.zoomTo(viewer.entities);

``

``