rotate polygon around point

Hey

Hello everyone

I’m trying to rotate a polygon around a point. How am I supposed to do this?

I’d love to help

Thank you

Hello,

There isn’t anything built into Cesium to handle this directly, but you can calculate the positions of the rotated points using a quaternion.

Here is a code example:

var viewer = new Cesium.Viewer(‘cesiumContainer’);
var positions = Cesium.Cartesian3.fromDegreesArray([-115.0, 37.0,
-115.0, 32.0,
-107.0, 33.0,
-102.0, 31.0,
-102.0, 35.0]);
var pointPosition = Cesium.Cartesian3.fromDegrees(-108, 38);
var quaternion = Cesium.Quaternion.fromAxisAngle(pointPosition, Cesium.Math.toRadians(1));
var rotationMatrix = Cesium.Matrix3.fromQuaternion(quaternion);
function getPositions(){
for (var i = 0; i < positions.length; i++) {
positions[i] = Cesium.Matrix3.multiplyByVector(rotationMatrix, positions[i], positions[i]);
}
return positions;
}

viewer.entities.add({
polygon : {
hierarchy : new Cesium.CallbackProperty(getPositions, false),
material : Cesium.Color.RED
}
});

viewer.entities.add({
position : pointPosition,
point : {
pixelSize : 10,
color : Cesium.Color.YELLOW
}
});

``

Best,

Hannah

Thank you Hannah :slight_smile:

‏בתאריך יום שלישי, 1 במרץ 2016, Hannah Pinkos pinkos.hannah@gmail.com כתב: