vasturiano / three-conic-polygon-geometry

ThreeJS geometry for drawing polygons on a sphere
https://vasturiano.github.io/three-conic-polygon-geometry/example/countries-gdp-per-capita/
MIT License
40 stars 14 forks source link

Inaccurate Polygons #8

Open seb-jones opened 1 year ago

seb-jones commented 1 year ago

Hello there,

Many thanks for making this awesome package!

I have noticed that some country polygons from the Natural Earth data don't render correctly. This can be seen by removing the wireframe: true from this line in the Countries example and rotating/zooming to Iceland:

image

You can see that the triangles aren't correct. Now, I notice that raising the curvatureResolution parameter in the THREE.ConicPolygonGeometry constructor to 5 seems to fix that:

image

But this breaks other country polygons, such as the nearby Greenland.

Is it possible to configure the ConicPolygonGeometry to get the polygons perfect?

Cheers

Seb

vasturiano commented 1 year ago

@seb-jones thanks for reaching out.

As you pointed out this is related to the precision of the curve in the shape as it follows the contour of the sphere. The more precise that curve is the less likely it is to encounter rendering artifacts like these. But it also fragments the geometry much more into smaller and smaller fragments, so the additional number of faces becomes a strain for the WebGL to render.

What's important to notice here is that a smaller value means higher precision. Essentially it represents the angular distance (in degrees) of the gaps n the quantizing "grid". So 5 is much lower definition than 1 actually.

seb-jones commented 1 year ago

Hi @vasturiano

Thanks very much for the response. I guess my question is, is there a way to make sure the polygons are always perfect? Because I noticed similar issues regardless of what precision I specified.

All the best,

Seb

vasturiano commented 1 year ago

@seb-jones because this method is an approximation of the sphere's curvature it will never be 100% perfect. But the idea is that as you lower the degree amount in the curvatureResolution parameter you get closer and closer to perfection, albeit with a performance penalty.