# Intersection and overlapping of polygon

**URL:** <https://community.cesium.com/t/intersection-and-overlapping-of-polygon/20026>\
**Category:** CesiumJS\
**Created:** [August 18, 2022, 1:32pm UTC](https://community.cesium.com/t/intersection-and-overlapping-of-polygon/20026 "2022-08-18T13:32:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamov](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/adamov/32/8236_2.png) [@adamov](https://community.cesium.com/u/adamov)\
**Post date:** [August 18, 2022, 1:32pm UTC](https://community.cesium.com/t/intersection-and-overlapping-of-polygon/20026/1 "2022-08-18T13:32:38Z")

</div>

Is there any code who fix intersection issue and overlapping of polygon?

 ![Polygon-intersection](https://global.discourse-cdn.com/cesium/original/3X/4/9/49f556937036702153d9866070f0a66b18bde0c1.jpeg)  
 ![Polygon-overlaping](https://global.discourse-cdn.com/cesium/original/3X/d/2/d209748e1020114df679aed659066a1ed8f06378.jpeg)

Thank you,  
Kind regards

---

<div class="post-metadata">

**Author:** ![Marco13](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/marco13/32/2757_2.png) [@Marco13](https://community.cesium.com/u/Marco13)\
**Post date:** [August 18, 2022, 1:55pm UTC](https://community.cesium.com/t/intersection-and-overlapping-of-polygon/20026/2 "2022-08-18T13:55:09Z")

</div>

To quote from [a related answer](https://community.cesium.com/t/polygon-object-snap-function/19947/2):

> I think that there is no “built-in” functionality for that (to be confirmed by the CesiumJS core team). The reason for that may be that it raises a few question about the desired interaction and details of the behavior …

🙂 Should you not be able to move the mouse into the other polygon? Should you just not be able to _click_ inside this polygon? Which sorts of (self-) intersections should be allowed or not?

On top of the question about interaction, this is not entirely trivial on a _technical_ level.

In 2D, polygon intersections are relatively simple, at least when you ignore performance and the inevietable difficulties that come with the limited floating point precision. For example, when you have a line from (0,0) to (3,1), then the point at (1,0.33333) should probably be considered to be _on_ this line, but in mathematics and in reality, it isn’t…

But here, we don’t have a **2D** editor. All this is happening in 3D, and the points that you are placing are _on the surface of earth_. So when you have a “unit square” with points like

```
(0.0, 0.0, 0.0)
(1.0, 0.0, 0.0)
(1.0, 1.0, 0.0)
(0.0, 1.0, 0.0)

```

Should you be able to set a point at (0.5, 0.5, 1.0)? Sure, when looking from above (as in the screenshot), then this point will appear to be “inside” the square. But in fact, it will be _above_ the square (because the square is at height `z=0.0`, and the point is at height `z=1.0`).

From what you described so far, it sounds like one could find a solution that is _roughly_ as follows: The points are projected on a plane that represents the tangent plane at the given position. The mouse position is also projected on that tangent plane. Then, the intersection and overlap tests can be done in 2D, on that tangent plane, but I’m not sure whether this is a viable approach…

Maybe someone has a good idea for a simple solution here, but I think that (even more than in the previous thread), there are some caveats that depend on subtle details of the implementation, the expected behavior, and the intended interaction patterns.

EDIT: You might consider to actually switch the viewer into 2D mode with `viewer.scene.mode = Cesium.SceneMode.SCENE2D`, and this _might_ simplify things here. But I haven’t used that extensively, and could not provide specific guidelines here.

---

<div class="post-metadata">

**Author:** ![adamov](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/adamov/32/8236_2.png) [@adamov](https://community.cesium.com/u/adamov)\
**Post date:** [August 24, 2022, 11:08am UTC](https://community.cesium.com/t/intersection-and-overlapping-of-polygon/20026/3 "2022-08-24T11:08:08Z")

</div>

@marco13 Thank you so much for your valuable reply.
