#### Archived

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

# Interpolation in 3d

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

## Recommended Posts

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 on other sites
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:
www.nr.com

lonesock

Piranha are people too.

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

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

/P2

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 18
• 20
• 14
• 14
• 9
• ### Forum Statistics

• Total Topics
633366
• Total Posts
3011527
• ### Who's Online (See full list)

There are no registered users currently online

×