Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sonicviz opened this issue Mar 27, 2023 · 3 comments

Comments

@sonicviz
Copy link

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!

@j-devel
Copy link
Contributor

j-devel commented Mar 29, 2023

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.

@sonicviz
Copy link
Author

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

@sonicviz
Copy link
Author

sonicviz commented Apr 1, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants