0

I have a regularly sampled grid, x,y,z and variable v. I would like to interpolate based on given x,y, &z values. I do not want to use numpy or scipy, because they are not installed on the platform I will be running on.

If I can locate the surrounding 8 grid nodes what math can I use to interpolate?

Thanks

1
  • 1
    A data structure example would be useful. Commented Nov 7, 2010 at 9:58

1 Answer 1

2

This actually seems to be a math question, but you also mentioned Python, so I try to give some code. You would usually use trilinear interpolation.

So we assume your grid has the corners (0.0, 0.0, 0.0) and (max_x, max_y, max_z) and is aligned with the coordinate system. We denote the number of cells along each axis by (n_x, n_y, n_z) respectively and the point you wish to evaluate at by (x, y, z) (all of type float). Then your logic might be something similar to

a_x = x * n_x / max_x
a_y = y * n_y / max_y
a_z = z * n_z / max_z
i_x = math.floor(a_x)
i_y = math.floor(a_y)
i_z = math.floor(a_z)
l_x = a_x - i_x
l_y = a_y - i_y
l_z = a_z - i_z

The indices of the 8 adjacent grid vertices now are (i_x, i_y, i_z), (i_x+1, i_y, i_z), (i_x, i_y+1, i_z), ..., (i_x+1, i_y+1, i_z+1). The local coordinates of your point within the grid cell are (l_x, l_y, l_z). Together with the linked Wikipedia article, this should get you going (note that the notation is different there).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.