Intersection and overlapping of polygon

To quote from a related answer:

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 …

:slightly_smiling_face: 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.

1 Like