+2  A: 

Have a look at Perlin Noise, it is a type of deterministic random data named after it's inventor Ken Perlin. If you search for "Perlin Noise" or "Ken Perlin" you will find a ton of articles on procedural textures and landscape generation.

kasperjj
Funny, looking through my old code to find a generated map to link to (I didn't find one) I saw these classes, but didn't remember what they were for: PerlinSolidNoiseGenerator.java and SolidNoiseGenerator.java. They were written by Carl Burke, according to the javadoc.
Peter Jaric
Wording of this answer is wrong - Perlin Noise is a deterministic sequence of pseudo-random data, not the other way around (there are functions that are deterministic and pseudo-random that are not Perlin Noise). http://en.wikipedia.org/wiki/Perlin_noise
Unreason
unreason: true! thanks...
kasperjj
+1  A: 

What you've got is pretty much the only way to do it - basically you've created a function, f, which gives geographical data for f(x,y). Of course, you can have several functions which you use to build up the terrain.

In addition to Perlin Noise, lookup fractal landscape generation. These can produce some very naturalistic loooking terrain.

Skizz
I do not know very much about fractals, and I wonder if fractal landscape generation can be used to generate two overlapping rectangles separately without having any differences in the overlapping parts? I think that is kind of the most important aspect of my question.
Peter Jaric
And another thing, is smoothing really the way to go?
Peter Jaric
@snowlor, yes fractals can do that, for example random midpoint displacement fractal - it takes as input the border values. To make it perfectly fit you would have to modify a bit the usual procedure (which takes only the corners) and make it work with known overlapping values. They are also good for dynamic LOD. For smoothing - you will have to tweak yourself; some terrains are more smooth and some are less smooth.
Unreason
+2  A: 

Normally, all terrain/world generators work in the way you described - they are able to produce vast (random-looking) worlds from a very limited input data (set of parameters).

So, you might want to put further constraints on your question.

If anything will work for you or if you are just begging to research - take a look at different focuses and approaches here.

As for randomness/deterministic I am not sure that you really talk about randomness here and it can be a bit confusing, I think you only want to be able to create a lot of variations. So you might want to drop that from your search terms.

Take a look also at procedural generation (especially 'see also' and 'external links').

Personally, I think there is a lot of promise in the concept of terrain synthesis where you basically mix and match real terrain samples with some sort of transforming operations - which provides realistically looking terrain with desired properties.

EDIT: Here's an implementation of 'plasma fractals' (mid-point displacement) in processing.

If that is good enough for you then you could rework the algorithm to allow it to generate any part of the grid (I have a feeling it will boil down to hashing the coordinates to get random number seed around connecting lines, or everywhere).

Also you might work with different levels of detail with this method so that you can generate more detail closer to the point of view.

Unreason
It appears the additional constraint is that he also wants to generate it on-demand - so each part of the map must be largely independent of the rest of it.
Nick Johnson
@Nick: yes, exactly.
Peter Jaric
@snowlord, that should not be such a problem with terrain synthesis (nor with most of the other methods, the only one I can think of is erosion simulation that would be sensitive to your requirement; but even then there are ways to deal with it - pre-computing the grid as border conditions).
Unreason
Also read on the links I provided; for your question I think it would be best to define the following: required performance, memory requirements, required detail (flight sim differs from game where you only crawl), required types of objects and object properties to generate (water/land - terrain type, vegetation - terrain cover, other artefacts - roads, rail, cities, etc...).
Unreason
If you can provide a mockup of what you are aiming for as a picture it will be much more clear.
Unreason
I will update my question in a while with a more detailed specification and also show what I mean with some images.
Peter Jaric
+2  A: 

Terrains are typically generated with fractals.

A simple method is Plasma Cloud algorithm, also known as Midpoint displacement algorithm. The general idea is:

  1. Set some altitude values for the corners of the area.
  2. Divide the rectangle into 4 smaller rectangles.
  3. Calculate altitude for the new points as average of the surrounding points and add some random displacement value to that
  4. Recursively divide each rectangle into smaller rectangles, and reduce the amount of displacement accordingly.

The random value is generated with a pseudo random number generator. If you give specific seed at the beginning, the same sequence of numbers is always generated.

Plasma cloud automatically generates smooth transitions, so no additional smoothing filter is needed.

Plasma cloud gives quite realistic landscapes, but they become boring in long term. Therefore, more complex algorithms (Perlin Noise, Ridged Perlin, etc.) may be used in addition. To get more variety, you could use one fractal (with low resolution) to adust the parameters of another fractal that calculates the actual values.

Fractals can be used to create textures and bumpmaps, too.

A good example of a program that generates landscapes with fractals and other procedural methods is Terragen. Terragen generates photorealistic images, so it is slow, but it has OpenGL preview that creates the landscape on-the-fly.

Edit: The problem with Plasma Cloud is that you can not generate a single point (or a small area) without generating the whole area. This is because it normally uses random number generator, which is dependent on the previous random number value.

However, you do not really need statistically good random number generator to generate terrain. Thus, you could replace the rand function with some function that calculates the random number from X and Y coordinates instead of previous value. Something like this (untested):

const int a = 0x7fffffff / 48271;
const int b = 0x7fffffff % 48271;

int displacement(int x, int y)
{
    int     seed, result;

    seed = x ^ ((y << 1) & 0x2AAAAAAA) ^ ((y >> 1) & 0x33333333);
    result = 48271 * (seed % a) - b * (seed / a);

    Return (result & 0xffff);
}

The above was modified from actual random number generator so that the seed is calculated from x and y. But maybe even some simpler function would be sufficient.

Edit2: To create infinite world, you can start for example with a rectangle of 10km x 10km. Use the displacement function above to set initial altitudes for the corners of the rectangle within which your target location is. Then start splitting the squares with Plasma Cloud algorithm. You only need to split and calculate those squares you are interested in, so you will quickly reach the target area (it is much like binary search).

PauliL
I think Plasma Clouds was what brought me into this, but the requirement to set the border values makes it impossible to use, since these are unknown and must be generated too. Or is it possible to do away with them using some variant of Plasma Clouds?
Peter Jaric
If you only need a large (but not infinite) world, you could initially create a low resolution array of altitudes and seed values using plasma cloud, for example 256 x 256 array with 1km resolution. Then use plasma cloud to fill the 1x1 km area as needed. Or you could calculate the seed value for each corner of the 1x1 km square on the fly using some function f(x,y).
PauliL
But the corners are not enough, are they? If I only have the corners, then two adjacent squares will not transition smoothly, if I am correct?
Peter Jaric
That is true. You would need to either modify the Plasma Cloud algorithm so that it would calculate edges first. Or replace the random number generator with some stateles function. I have now updated the answer.
PauliL
A: 
andand