Results 1 to 10 of 10

Thread: Terrain smoothing?

  1. #1

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Terrain smoothing?

    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?

    This is the current output of my program:
    Attached Images Attached Images  

  2. #2
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: Terrain smoothing?

    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

    <- Remember to rate posts you find helpful.

  3. #3

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: Terrain smoothing?

    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?

  4. #4
    Junior Member
    Join Date
    Aug 2007
    Posts
    17

    Re: Terrain smoothing?

    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

  5. #5

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: Terrain smoothing?

    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?

  6. #6
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Terrain smoothing?

    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!

  7. #7
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: Terrain smoothing?

    Have you considered modifying a cycloid to make it 3D?

  8. #8
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Terrain smoothing?

    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
    Attached Images Attached Images  

  9. #9
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: Terrain smoothing?

    Very pretty..

  10. #10

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: Terrain smoothing?

    That is pretty impressive. I'll have to play around with that. Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width