#### Archived

This topic is now archived and is closed to further replies.

# interpolation algorithm

This topic is 6721 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
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

##### Share on other sites
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);

##### Share on other sites
Hmm, the diagram should show a rectangle with the ''a'' near the top left.
X and Y are the coordinates of point ''a''.

##### Share on other sites
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;

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

1. 1
Rutin
36
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633344
• Total Posts
3011438
• ### Who's Online (See full list)

There are no registered users currently online

×