Hi folks,
I'm still around here and I need a little bit of help to write a simple mapgen.
I want to write a mapgen that creates a surface withe the same radius of the earth an a hight resolution of 1/16 block.
That means that I get 64*64km sphere section with the same radius as the earth.
I'm not sure how to calculate that, especially with the 1/16 blocks.
Can someone help me?
Thanks
burli
How to calculate a spherical surface?
- DrFrankenstone
- Member
- Posts: 231
- Joined: Tue May 24, 2016 05:36
- GitHub: treer
- Location: Australia
- Contact:
Re: How to calculate a spherical surface?
A formula for a sphere is: x² + y² + z² = r²
so rearrange that for y gives y = sqrt(r² - x² - z²)
The radius of earth is 6,371 km, so y = sqrt(6371000² - x² - z²)
But that earth is centered on (0,0,0) and you probably want it centered 6371km lower so that ground level at x=0, z=0 will be at y=0, so
y = sqrt(6371000² - x² - z²) - 6371000
Since Minetest's Lua doesn't have bitwise operators, you could get the 1/16 fractional values out of y like:
(None of this is tested, and I couldn't tell if I understood the question, any mistakes left as exercises for the reader :))
so rearrange that for y gives y = sqrt(r² - x² - z²)
The radius of earth is 6,371 km, so y = sqrt(6371000² - x² - z²)
But that earth is centered on (0,0,0) and you probably want it centered 6371km lower so that ground level at x=0, z=0 will be at y=0, so
y = sqrt(6371000² - x² - z²) - 6371000
Since Minetest's Lua doesn't have bitwise operators, you could get the 1/16 fractional values out of y like:
Code: Select all
yTruncated = math.floor(y)
sixteenths = math.floor(y * 16) - (yTruncated * 16)
Last edited by DrFrankenstone on Wed Sep 19, 2018 15:50, edited 3 times in total.
Who is online
Users browsing this forum: Bing [Bot] and 40 guests