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 .