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


Interpolation in 3d

Recommended Posts

P2    122
Hi, I have a vessel with a position on an x-y grid and want to calculate the vessel''s position in the z direction, the height. There are only a few points scattered around the grid where the z is given so on the rest of the points I have to interpolate the height from these points. Could I just use the three closest points and make some kind of weighted average between them or should I calculate some kind of height curves for the grid? A problem is that this should all happen in real-time so it can’t be too computationally expensive. I’m thankful for all the help I can get. Does anyone know of a good page for interpolating and calculating averages and so on? I often seem to end up with these kind of problems. Regards, P2

Share this post

Link to post
Share on other sites
lonesock    807
If there really are just a few control points, this might be the easiest:

z_final = 0.0;
z_weight = 0.0;
for (i = 0; i < NumPoints; ++i)
dx = pt.x - my_x;
dy = pt[i].y = my_y;
this_weight = 1.0 / (1.0 + dx*dx + dy*dy); // add 1 so no "if 0"
z_final += pt[i].z * this_weight;
z_weight += this_weight;
z_final /= z_weight; // "normalize"

note that cycle saving measures like finding the 3 closest points are expensive too. I say try it and see.

numerical recipies (sp?) is a great resource for algo's:


Piranha are people too.

[edited by - lonesock on March 30, 2004 4:09:11 AM]

Share this post

Link to post
Share on other sites
P2    122
I''ll try that idea, It''s not always the same amount of control points but when there are just a few I believe this will be quite good, since as you pointed out, finding the 3 closest points can be expensive.

Guess I have to go for some triangulation when there are too many points.


Share this post

Link to post
Share on other sites