# BTF Find Four Closest Sampling Directions

I am trying to use the techniques discussed in this paper to implement a BTF into PBRT. I am stuck on how to actually interpolate the weights of the four closest sampling directions.

At the BTF, I have converted $$w_o$$ and $$w_i$$ from cartesian to spherical coordinates in order to do a lookup in the table of BTFs. The samples are taken with the following properties:

$$\theta$$ light (and view angles) range from 0 to 75 in 15 degree increments. $$\Delta\phi$$ at each $$\theta$$ goes from 0 to (360 - $$\Delta\phi$$) at -, 60, 30, 20, 18 and 5 degree increments respectively. In a table:

$$\theta$$ $$\Delta\phi$$ (0 - (360 - $$\Delta\phi$$))
0 -
15 60
30 30
45 20
60 18
75 5

How can I determine the four closest sampling directions given $$w_o$$ and $$w_i$$? Retrieving the values/weights seems trivial, but I don't really have a clue on how to determine the four nearest directions and just don't know where to start.

const float table[6] = {0,60,30,20,18,5};

The above is implemented as the step function in increments of 15. The last bit of the result is a range check that can be used to zap out of range values. (theta>range) evaluates to zero or one.