0

Say I have an array of 5x5. If I know the following points [1,1] = 40, [1,3] = 50, [3,1] = 60, [3,3] = 70, how do I calculate each unknown point in the array? Basically I'm doing an algorithm for a gradient map, of say, temperatures on a map.

Thanks

dave2118
  • 206
  • 6
  • 22
  • 2
    This is more of a math question than a programming one, but strangely, there is a similar thread on SO: [Simple way to interpolate between points in 3D space to form a smooth surface](http://stackoverflow.com/questions/313297/simple-way-to-interpolate-between-points-in-3d-space-to-form-a-smooth-surface) – vgru Sep 07 '11 at 12:07
  • 1
    First find the math needed to do what your asking, and then we'll show the code to implement that. I'm not exactly sure what you mean by 'calculating the unknown point in the array'. – Jeff Reddy Sep 07 '11 at 12:17
  • To add to the above comments: suppose you model this situation physically, using sticks of different lengths positioned on a chessboard. It's easy to see that there are an infinite number of surfaces that fit the points you have - first decide how you are going to pick the surface you want, then work out how you would work out the intermediate values, and *then* you can work out how to code it. [math.se] may be of help. – AakashM Sep 07 '11 at 13:29
  • Is it a static gradient of conductive heat with boundary conditions? A medium undergoing an exothermic reaction (e.g. combustion or nuclear decay)? A furnace wall with inadequate insulation? Those three cases will have very different solutions. – Beta Sep 07 '11 at 14:13
  • This is actually for energy frequency between different power stations. It will work exactly like temperatures on a weather chart. I'm trying to simplify it to make sure my math is correct before plotting around 1000 pieces of data a second. – dave2118 Sep 07 '11 at 14:55
  • Can you be more precise? Do you have an example of problem and solution? It looks like you want to interpolate, but I think you can't do it without boundary conditions. – Andrea Ambu Sep 07 '11 at 18:34
  • I think we have a better understanding. Basically I'll use `code`Sqrt(x1-x2)^2+(y1-y2)^2) `code` which will give me the distance between points. From there, I took everything on a percentage level and factored in the weights off of that. This seems to work well, but not sure if we're there yet. – dave2118 Sep 07 '11 at 20:09

1 Answers1

1

I'll lay out the algorithm for you in pseudo code to find the weight of any point p

Find the two point p1 and p2 that are on the "left" and "right" of p
distance = distance(p1, p2)
distance_p1 = distance(p, p1)
weight_diff = p1.weight - p2.weight
weight_p = p1.weight + (distance_p1 / distance) * weight_diff

Let me know if anything is unclear.

EDIT: This assumes linear interpolation in between points.

beetree
  • 871
  • 2
  • 8
  • 18