interpolation algorithm

Started by
3 comments, last by neoGriff 23 years, 10 months ago
Can anyone help me out with getting started on an algorithm for height map interpolation? I want to be able to set up a height map with random values set for every "a" pixels horiz. and vert.. Then I want to be able to go through pixel by pixel and find the correct height for the pixel based on the distance of the pixel from each of the four height map values around it. Like this: 1 4 x 5 8 What would be the height of x?
Advertisement
I''m not sure if I realy understand what you says but I think this link can help you:
http://freespace.virgin.net/hugo.elias/models/m_perlin.htm

Floyd
For a map like this. ''a'' is the position you want. X is positive to the right, and Y is positive going down. With X0 and Y0 being the coords of the top-left. Width ( distance 1->2 or 3->4 ) is W. Height is H

1.......2
. a .
. .
. .
. .
3.......4

If you let h1 be the height of point 1, h2 be the height of point 2 etc

Using linear interpolation:-

float X1=(X-XO)/W;
float Y1=(Y-Y0)/H;

float X2=1.0f-X1;
float Y2=1.0f-Y1;

Height = (h1*X2*Y2)+(h2*X1*Y2)+(h3*X2*Y1)+(h4*X1*X2);

Hmm, the diagram should show a rectangle with the ''a'' near the top left.
X and Y are the coordinates of point ''a''.
I just scribbled this down without really thinking about it (I'm at work =P). It's probably wrong, but may help nonetheless:

Given:

Constants of four heightmap points X1, X2, Z1, Z3.
Variable of one point N inside the bounds of above constants.

It is assumed that (X2 > X1) && (Z2 > Z1), and that points have members variables X, Y, and Z. Also, we are assumed to know the X and Z portions of the point N, but not the Y component.

We do:

float A = X1 + ((X2.Y - X1.Y) * ((X2.X - X1.X) / max(X2.X, N.X)));
float B = Z1 + ((Z2.Y - Z1.Y) * ((Z2.X - Z1.X) / max(Z2.X, N.X)));
N.Z = (A + B) / 2;

[edit]
Hmm. Come to think of it, maybe the two max() statements should be replaced with "(N.X - X1.X)" and "(N.X - Z1.X)", respectively.
[/edit]

Edited by - revolver on June 22, 2000 1:07:24 PM
Creativity is a bloody nuisance and an evil curse that will see to it that you die from stress and alcohol abuse at a very early age, that you piss off all your friends, break appointments, show up late, and have this strange bohemian urge (you know that decadent laid-back pimp-style way of life). The truly creative people I know all live lousy lives, never have time to see you, don't take care of themselves properly, have weird tastes in women and behave badly. They don't wash and they eat disgusting stuff, they are mentally unstable and are absolutely brilliant. (k10k)

This topic is closed to new replies.

Advertisement