Convert polygon to Rectangle

Hi,

I have for 4 Cartesian3 points of a polygon and I want to create a rectangle from these (must be same with polygon).

Are there any easy way to do this except finding width/height and center point and then calculate rectangle, because it’s a waste of a memory in my case. The other way that I thought is finding westernmost long, southernmost lat, easternmost long and northernmost lat but that’s not easy as I thought.

I tried to use:

var rec = viewer.entities.add({
    rectangle : {
        height: 0,
        coordinates : Cesium.Rectangle.fromCartesianArray(cartesianArray),
        material : Cesium.Color.BLUE.withAlpha(0.5)
    }
});

But the problem is, when the actual polygon was blue, rectangle created like red one even they have same coordinates because it take as westernmost, southernmost etc.:

Any ideas about it?

Here’s Sandcastle link: https://sandcastle.cesium.com

Thanks in advance.

Hi @Hazel-Leylak,

sadly, I dont quite understand what you want to do, so i have to ask.

Is this what you want to do?


This is just a quick and dirty paint-edit!

Or do you want the red rectangle, but are not satisfied with its shape?

Best, Lennart

Hi @lennart.imberg,

I want to do red rectangle as same as the blue one. Blue is a polygon (I created it with 4 cartesian point info), so basically I want to convert my polygon to rectangle. So, blue and the red one should be same. (Their angles must be same too)

Hope I expressed myself well.

Regards,

OK, now I understand, @Hazel-Leylak.
Sadly, that is not possible to my knowledge. The Cesium.Rectangle must be like in your photo. Its not possible to “rotate” it, because its build from westernmost, northernmost… borders as you already noticed. That is fixed with this function in the Cesium code.

So you will have to rely on a polygon.

Best, Lennart

1 Like