MightyBOBcnc / nixis

A python program for procedurally generating planet-scale maps for Earth-like, spherical worlds.
MIT License
8 stars 0 forks source link

Examine slope calculation for unexpected values #6

Open MightyBOBcnc opened 1 year ago

MightyBOBcnc commented 1 year ago

A number of attempts at hydraulic erosion (erosion.py) have all resulted in unstable sims that produce spikes or chasms in the terrain:

image

One avenue to investigate is the calculation of the slope between vertices. In both calc_slope and calc_slope_deg a tiny value was added to the distance between verts to prevent divide by 0 failures. (v1 - v0) / (dist + 0.00001) In theory the distance between verts should be measured in kilometers and this tiny added value should be irrelevant, but if somehow the distance is a very small number the result could be that the rise (v1 - v0) measured in meters, over the run (dist + 0.00001) could be taking a larger number and dividing by a very tiny number which would result in a return value measured in the hundreds of thousands or millions.

Instead it might be prudent to conditionally check the distance and/or the rise and return a slope of 0 if the values are essentially flat or too close to each other.

Also while we're at it we should double check calc_distance and validate what it is outputting since it is part of the same chain of functions.

MightyBOBcnc commented 1 year ago

For a mesh with around 1 million vertices (frequency = 320), the slope between elevations at any two vertices is rarely above 1 degree (but is sometimes up to 2 or 3 degrees), and is usually more like 0.0N or 0.N degrees, because the distance between vertices is around 24km. This is a long distance and the slope change will be pretty gentle, despite what the exaggerated scale might look like in the PyVista viewer.

So, indeed, the slope number will be quite small, so dividing anything by the slope would make a big number.

MightyBOBcnc commented 1 year ago

Also, at the moment the heights are remapped to a range that includes negative numbers (e.g. -4000 meters to positive 8000 meters) and the negative numbers being fed into the slope functions (not to mention the addition/subtraction that happens in the erosion uptake/deposition) could be having undesired effects. It might be best to temporarily move the entire range upward so that the lowest elevation is 0 while running the erosion and then move it back down once erosion is complete.