vasturiano/three-globe

Some polygons from geojson data have holes in caps...

andrewleek-droplab opened this issue · 2 comments

First off, i just wanted to say awesome work on this project! Thank you so much for all your hard work on this!

Problem:
Most of the polygons are drawn fine, but there are a few that seem to have areas missing on the caps, although the data seems to be there because the edges are visible, as well as the sides. I am using the same geojson data at you are, and when previewing those files in various viewers, the holes are not there. This makes me think this must have something to do with how the geojson country coords are being drawn/parsed (to me it almost looks like the points are being drawn out of order sometimes...) I have attached a few screenshots from your choropleth example

Im thinking the issue may lie in: https://github.com/vasturiano/three-conic-polygon-geometry

Can you shed some light on why this may be happening?

  • OS: OSX
  • Browser Chrome
  • Version 88.0.4324.192

Screen Shot 2021-03-02 at 4 23 15 PM
Screen Shot 2021-03-02 at 4 23 02 PM
Screen Shot 2021-03-02 at 4 22 31 PM

Quick follow-up on this:
After messing around with the curvatureResolution, it would appear that this artifact is related to said curvatureResolution. It appears by default it is set to 5, and if i lower it, it gets better but different (smaller) artifacts can still appear. Oddly if i set it higher (ie 10 or even all the way 90), the issue goes away. I would assume that if i went higher, that the curvature of the caps would become more facetted, but they look fine....

@andrewleek-droplab thanks for raising this issue.

I think I understand why this is happening. It's an interesting artifact, and possibly a bit tricky to fix.

It is indeed related to the three-conic-polygon-geometry module, and more specifically to the curvatureResolution computation, as you mentioned.

First, let me mention why adding curvature to the polygon caps is necessary. If the polygon surfaces are straight planes, when plotted on the earth's round surface they will literally cut right through the surface, and have the inner sections disappear, as if they are "underground" compared to the edges.

curvatureResolution solves this problem by interpolating the whole surface of each polygon and breaking the area into smaller triangles which are angled, to try and approximate the curved surface of the globe. The resolution value (in spherical degrees) defines the longest side of a triangle that is allowed while doing this triangle fragmentation. So, the lower the resolution value the more fragmentation occurs and the smaller the triangles, while for higher values the less the original polygon is transformed. For values > 180º, you're essentially plotting the original polygon shape (albeit with the problems mentioned above).

This wireframe example demonstrates this triangulation effect on the geojson (with the default resolution of 5º): https://vasturiano.github.io/three-conic-polygon-geometry/example/countries/

Now, the issue this fragmentation process introduces is that when two or more adjacent polygons are fragmented separately, the boundaries between them don't necessarily end up with the same shape, due to the interpolation. I believe this tends to happen only in places where at least 3 polygons join. In direct borders between 2 the final shape should be the same for both as fragmentation is using the same input numbers. It's when you have the joint of 3 or more that the input contours are different, leading into potential gaps (or overlaps) in those areas. I believe that's the root cause of the artifacts you're observing.

Also, as you mentioned, increasing the resolution distance makes the problem go away as it's essentially bypassing the fragmentation step. While lowering the number makes the gaps appear smaller and smaller as the vertices in the contour are getting more defined and closer together so the affected areas keep shrinking.

This is the explanation of the issue, but of course you're still no closer to know how to fix it. For now, the main thing I can think of is to decrease the curvatureResolution until they are at a point that it's no longer disturbing. That is a compromise between the visuals and the cpu performance it takes to do the fragmentation logic and render more complex geometries. It's a bit of a patchy way, but perhaps there's a more elegant manner to fix this that I'm not seeing at the moment.