Given an n by n matrix M, at row i and column j, I\'d like to iterate over all the neighboring values in a c
What I would do is use the equation for an Archimedean spiral:
r(theta) = a + b*theta
and then convert the polar coordinates (r,theta) into (x,y), by using
x = r*cos(theta)
y = r*sin(theta)
cos and sin are in the math library. Then round the resulting x and y to integers. You can offset x and y afterward by the starting index, to get the final indices of the array.
However, if you are just interested in finding the first radius where f returns true, I think it would be more beneficial to do the following pseudocode:
for (i,j) in matrix:
radius = sqrt( (i-i0)^2 + (j-j0)^2) // (i0,j0) is the "center" of your spiral
radiuslist.append([radius, (i,j)])
sort(radiuslist) // sort by the first entry in each element, which is the radius
// This will give you a list of each element of the array, sorted by the
// "distance" from it to (i0,j0)
for (rad,indices) in enumerate(radiuslist):
if f(matrix[indices]):
// you found the first one, do whatever you want