I would like to determine the contour of a boolean function defined over two variables, each in the 0, 1 range. I do not have access to the explicit form of the function: it is a black box that returns a boolean for each pairs of variables, so I don't know how to convert it to a continuous function and use the first answer below. The region is convex, and it may reach the edges of the ranges of the parameters. Language is python. The function may be expensive to calculate, so the brute force grid approach I have below is slow in addition to being inaccurate. How can I improve things?
import numpy as np
import matplotlib.pyplot as plt
def f(x, y): return ((x-0.3)**2+(y-0.4)**2 <= 0.1) # Example of function; may extend outside region. In reality, form is not known.
xs, ys = np.linspace(0, 1, 11), np.linspace(0, 1, 11) # Brute force grid
for x in xs:
for y in ys: plt.plot(x, y, 'ro' if f(x, y) else 'b+')
cntr = [] # List of unique, approximate contour points
for x in xs:
col = [y for y in ys if f(x, y)]
if (col != []) and (not ((x, min(col)) in cntr)): cntr.append((x, min(col)))
if (col != []) and (not ((x, max(col)) in cntr)): cntr.append((x, max(col)))
for y in ys:
row = [x for x in xs if f(x, y)]
if (row != []) and (not ((min(row), y) in cntr)): cntr.append((min(row), y))
if (row != []) and (not ((max(row), y) in cntr)): cntr.append((max(row), y))
plt.plot(np.transpose(cntr)[0], np.transpose(cntr)[1], 'kv') # Contour in black
plt.show()



