# Convert polygon to Rectangle

**URL:** <https://community.cesium.com/t/convert-polygon-to-rectangle/17117>\
**Category:** CesiumJS\
**Created:** [February 1, 2022, 7:33am UTC](https://community.cesium.com/t/convert-polygon-to-rectangle/17117 "2022-02-01T07:33:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hazel-Leylak](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hazel-leylak/32/7979_2.png) [@Hazel-Leylak](https://community.cesium.com/u/Hazel-Leylak)\
**Post date:** [February 1, 2022, 7:33am UTC](https://community.cesium.com/t/convert-polygon-to-rectangle/17117/1 "2022-02-01T07:33:22Z")

</div>

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:

```auto
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.:

 ![image](https://global.discourse-cdn.com/cesium/original/3X/b/0/b04044f720ec07a266ae6274b9f39d8445aa89e7.jpeg)

Any ideas about it?

Here’s Sandcastle link: [https://sandcastle.cesium.com](https://sandcastle.cesium.com/index.html#c=fZPLbtswEEV/RfBKBgSaT5FMHaOpm12AAuljU3VBS4xFlCINSnbgFPn3UnL8TOBZiaM7Z+4MpY0KycboZx2S28Tp52SuW7NuwK8hlxajcjjPveuUcToUo/GnwhVuE+vUeclchS4+KUdSklOUYwgw5AQiySjJEkIRQhwDKankmOeCZ0QySbkEkGFGOJI47+E9enEFjYUUCHCKKRcRMKAhZ0gAhCAUlBOUx5zkFEEKIEeEMJYzsmeXV9gE5zmMHJ5jKTjs2UTKPkcxwiJnA5hTKgHCuexV8mC6urYPRqAEuRA4doij954JgQRQKTGNQQbPcTiCgMSERfdCHHdd7mF3IahtbPRbZYuszKo/B0nQ1aMuO+WWVkfB7laBdp3pjG6Bqqr0X+GSGOEgu0neUn3U2izr7iaB2TFXeh8q41RsHsVvkx3agKfgm/mZtfTc6fiE1URKMMoeQXNvfQCP91/Bs+nqO7uqVRq/mvGu5rVwr8cNrLzdLr27PtledDJXbXRQoay3MXnu7WBtb+zC15eHn/dnxth7YzsrL943P3x6YayXjLLRtO22Vs/2zT6bZuVDl6yDTQGYdLpZ2X69k8W6/Ks7ULZDYS+dTk5Lp5XZJKa6/eCfTEqr2ja+eVpb+9286GI0m06i/l2p9Spe5/LbRgertr2sRrOHXRIAMJ3E48eVnfd2ocIF+T8)

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![lennart.imberg](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/lennart.imberg/32/9788_2.png) [@lennart.imberg](https://community.cesium.com/u/lennart.imberg)\
**Post date:** [February 1, 2022, 12:53pm UTC](https://community.cesium.com/t/convert-polygon-to-rectangle/17117/3 "2022-02-01T12:53:00Z")

</div>

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?

 ![b04044f720ec07a266ae6274b9f39d8445aa89e7](https://global.discourse-cdn.com/cesium/original/2X/2/2b746e3d60b0c26d9dc8ef4aea581df51394e25c.jpeg)  
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

---

<div class="post-metadata">

**Author:** ![Hazel-Leylak](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hazel-leylak/32/7979_2.png) [@Hazel-Leylak](https://community.cesium.com/u/Hazel-Leylak)\
**Post date:** [February 1, 2022, 1:39pm UTC](https://community.cesium.com/t/convert-polygon-to-rectangle/17117/4 "2022-02-01T13:39:33Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![lennart.imberg](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/lennart.imberg/32/9788_2.png) [@lennart.imberg](https://community.cesium.com/u/lennart.imberg)\
**Post date:** [February 2, 2022, 7:17am UTC](https://community.cesium.com/t/convert-polygon-to-rectangle/17117/5 "2022-02-02T07:17:18Z")

</div>

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
