I am trying to get a corner coordinates of rotated rectangle. Then, create a polygon with these coordinates.
So far, I tried to use Rectangle.nortwest, southeast etc. functions but it gives me coordinates before rotation.
Here’s my code: Cesium Sandcastle
var viewer = new Cesium.Viewer("cesiumContainer");
var tl = Cesium.Cartographic.fromDegrees(43.92666513491127,37.413199590790164,0);
var tr = Cesium.Cartographic.fromDegrees(44.142734829047264,37.413199590790164,0);
var bl = Cesium.Cartographic.fromDegrees(43.92666513491127,37.29166038783867,0);
var br = Cesium.Cartographic.fromDegrees(44.142734829047264,37.29166038783867,0);
tl = Cesium.Cartographic.toCartesian(tl);
tr = Cesium.Cartographic.toCartesian(tr);
bl = Cesium.Cartographic.toCartesian(bl);
br = Cesium.Cartographic.toCartesian(br);
var cartoArr = [bl, br, tr, tl];
var convRect = viewer.entities.add({
rectangle : {
coordinates: Cesium.Rectangle.fromCartesianArray(cartoArr),
material: Cesium.Color.PURPLE.withAlpha(0.7),
rotation: -46.22552065940672
}
});
var rect = convRect.rectangle.coordinates._value;
var northeast = Cesium.Cartographic.toCartesian(Cesium.Rectangle.northeast(rect));
var northwest = Cesium.Cartographic.toCartesian(Cesium.Rectangle.northwest(rect));
var southwest = Cesium.Cartographic.toCartesian(Cesium.Rectangle.southwest(rect));
var southeast = Cesium.Cartographic.toCartesian(Cesium.Rectangle.southeast(rect));
var cartes = [northwest, southwest, southeast, northeast];
var polygonFirst = viewer.entities.add({
polygon : {
hierarchy : cartes,
material: Cesium.Color.GREEN.withAlpha(0.8),
}
});
polygonFirst.polygon.stRotation = -46.22552065940672;
viewer.zoomTo(convRect);
Any idea about converting rectangle to polygon?
You have to calculate rotated positions using Matrix operations.
Here's Sandcastle link