So I have this program... it creates (or I create) a set of "High points", which end up being the only predefined locations on the map. The program then goes through every other point on the map and determines what that point's height should be based on its' distance to the high points. Right now, it uses a simple quadratic formula to smooth from the high point down, but this gets ugly the lower the altitude is. The goal is simple: smooth the slopes from between the points, making them "aware" of each other. I've tried a couple simple methods but have yielded no real results. Anyone have any ideas what the best way to do this would be?
Perhaps you could include (additively) the effects from all high points. As you get close to a "parent point" (the top of a "hill"), include effects from the other points less and less. I would say... for the closest high point, include your effects as you've done. For every other high point, add in their quadratic effects multiplied by the distance between the current point and its closest high point (divided by some constant determined by testing).
I *think* this'll give you a nice smooth transition between points. If you wanted to make sure you could write it up algebraically and take a derivative. The function should at least be continuous; it should be nice and smooth in the end.
The time you enjoy wasting is not wasted time. Bertrand Russell
Funny you should suggest that... that is precisely the idea I tried to implement... turned out to be a real pain. My guess is I just didn't have the right equations, as I was kinda slapping things in on the fly. Do you have any idea what the equations would look like and what the general behavior would be?
I was thinking maybe adjusting your equations so that once you hit a certain distance away from each high point, the equation that calcs the 'land' height changes to somekind of exponential decay... something with positive curvature or something that makes the 'ground' look more like a smiley face rather than a sad face, if you know what i mean
I'm pretty sure this will produce a plot that will not be continuous at points mid-way between high points.
let
x = the distance from the closest high point to point in question
y = the height of the point in question
H = the height of the closet high point
if x <= 2*H then y = -x^2 + ...whatever your quadratic formula is
if x > 2*H then y = 1/x
To make it look nice you would want to ensure that the two equations have the same slope (or at least the same y value) at the switch-over point (in this case, 2*H).
you would also want to make sure that y hits somekind of lower limit:
if x > 100*H then y = 0.0001 ...or something
The problem I faced with calculating based on the closest high point is that it's almost impossible to get that smooth flow. There's always a definite boundry as to which point is closest, because of the height differences. My thought is to "weight" each point based on the distance, and calculate something based on those ratios... that way, the closer a high point is, the more influence it has, but it doesn't create "boundaries" between points... Thoughts?
I'd go with jemidiah's approach.
Assume you have all positions of the HighPoints ( in an UDT with .Latitude ; .Longitude; .Height).
The height for a Point.Latitude=Lat ; Point.Longitude=Long could be calculated like this (it's based on the quadratic distance to each highpoint):
Code:
'Use interimHeight as Integer to store the value while counting
interimHeight=0
For i= LBound(HighPoints) to UBound(HighPoints)
interimHeight=interimHeight+HeighPoints(i).Height/((Lat-HeighPoints(i).Latitude)^2+(Long- HeighPoints(i).Longitude)^2)
Next i
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button Wait, I'm too old to hurry!
I thought I'd have a go at this...
I created a simple flat mesh and then used the Gaussian function to generate each peak. The mesh below is simply the product of adding the vertical coordinates of each peak.
Code:
Public Sub ApplyGaussian(ByVal OX As Long, ByVal OY As Long, ByVal Peak As Single, ByVal Decay As Single)
Dim X As Long, Y As Long, UBX As Long
Dim dy As Single, dx As Single, DSq As Single
Const E = 2.71828182845905
Decay = 2 * Decay * Decay
UBX = UBound(Mesh, 1)
For Y = 0 To UBound(Mesh, 2)
For X = 0 To UBX
dx = OX - X
dy = OY - Y
DSq = (dx * dx + dy * dy)
Mesh(X, Y) = Mesh(X, Y) + Peak * E ^ (-DSq / Decay)
Next X
Next Y
End Sub