three-geo icon indicating copy to clipboard operation
three-geo copied to clipboard

Q: How do you calculate terrain height relative to the position units in three.js, which are also dependant on the zoom factor?

Open sonicviz opened this issue 1 year ago • 3 comments

Q: How do you calculate terrain height relative to the position units in three.js, which are also dependant on the zoom factor?

For example, if I want to position an object 1m above sea level (which according to https://docs.mapbox.com/data/tilesets/guides/access-elevation-data/#mapbox-terrain-rgb sea level is 0) how do I translate that into a relative mesh position,z value that will translate it a unit of 1m (or 10m or whatever) relative to the scale of the mesh terrain elevation?

Also. how does that position calculation change based on the zoom factor, which can be from 11 to 17?

https://docs.mapbox.com/help/glossary/zoom-level/ doesn't give me much of a solution either.

Thanks!

sonicviz avatar Mar 27 '23 07:03 sonicviz

how does that position calculation change based on the zoom factor, which can be from 11 to 17?

The zoom parameter in the API is used to specify the "resolution" of the terrain object, and it has nothing to do with the position/rotation/scale of the object rendered by Three.js.

To illustrate this more clearly, I have updated the heightmap example so it can accept some of varying zoom values.

It would be helpful to compare these cases:

https://w3reality.github.io/three-geo/examples/heightmaps/index.html?zoom=11 https://w3reality.github.io/three-geo/examples/heightmaps/index.html?zoom=12 https://w3reality.github.io/three-geo/examples/heightmaps/index.html?zoom=13

where each rendered terrain is essentially the result of

const origin = [46.5763, 7.9904];
const radius = 5.0;
const terrain = await tgeo.getTerrainRgb(origin, radius, zoom)

if I want to position an object 1m above sea level

I would suggest following the projection example for that.

Specifically, how the z value of 3970m above sea level is mapped into WebGL space through multiplication by unitsPerMeter.

j-devel avatar Mar 29 '23 06:03 j-devel

OK, I'll give that a shot. Thanks.

sonicviz avatar Mar 29 '23 14:03 sonicviz

Looks like that works, thanks.

How accurate is that elevation calculation? Within some rough % range? I gather there will be some variance based on the quality of the dem and other factors?

"We’ve mapped these to 0.1 meter height increments, which gives us the vertical precision necessary for cartographic and 3D applications." ref: https://blog.mapbox.com/global-elevation-data-6689f1d0ba65

So up to 0.1m accuracy? (that mapbox post is from 2015, not sure if it's increased since then)

sonicviz avatar Apr 01 '23 08:04 sonicviz