# Drawing an approximate visualization of an inequality using ArrayPlot

I need to write a function that returns graphic visualization of the two-dimensional figure described with equation:

$$\qquad P = \{(x, y) \in R^2: 4+2x < x^2+y^2<9\}$$

I have to use the n x n matrix for this (n is the parameter of the function to write)

If I understand correctly, given the same problem but with circle as $$P$$ instead for $$n = 3$$, it would be something like this:

ArrayPlot[{{0, 1, 0}, {1, 1, 1}, {0, 1, 0}}]


I know that, in the problem stated above, I have an intersection of circle with the complementation of another circle, but I am at a lost on how to express the above equation in the form of a matrix and how to scale it with the manipulation of the parameter $$n \in N$$.

Make a function that captures the condition on {x,y}:

ClearAll[f]
f[x_, y_] := 4  + 2 x <= x^2 + y^2 <= 9


Here is the region defined by f:

rp = RegionPlot[f[x, y], {x, -5, 5}, {y, -5, 5}, PlotPoints -> 100]


Make a matrix using f:

matrix[f_][n_Integer, divs_: Automatic] :=  Module[{m = If[EvenQ[n], n, n + 1]},
Table[Boole[f[i, j]],
{j, -m/2, m/2 , m /(divs /. Automatic -> m)},
{i, -m/2, m/2,  m /(divs /. Automatic -> m)}]]

ap = ArrayPlot[matrix[f][9], Mesh -> All, DataReversed -> True,
DataRange -> {{-5, 5}, {-5, 5}}]


Show the region and array plots together:

Show[ap, rp]


Use the second argument of matrix to get finer subdivisions:

divs = 20;
Show[ArrayPlot[matrix[f][9, divs], Mesh -> None, DataReversed -> True,
DataRange -> {{-5, 5}, {-5, 5}}], rp]


divs = 100;
Show[ArrayPlot[matrix[f][9, divs], Mesh -> None, DataReversed -> True,
DataRange -> {{-5, 5}, {-5, 5}}], rp]


A more complicated region:

ClearAll[f2]
f2[x_, y_] := Xor[(-1/2 + x)^2 + y^2 < 1,
x + 4*x^2 + 4*y^2 < 3 + Sqrt[5]*x + Sqrt[2*(5 + Sqrt[5])]*y,
x*(1 + Sqrt[5] + 4*x) + 4*y^2 < 3 + Sqrt[10 - 2*Sqrt[5]]*y,
x*(1 + Sqrt[5] + 4*x) + y*(Sqrt[10 - 2*Sqrt[5]] + 4*y) < 3,
x + 4*x^2 + y*(Sqrt[2*(5 + Sqrt[5])] + 4*y) < 3 + Sqrt[5]*x];

rp = RegionPlot[f2[x, y], {x, -2, 2}, {y, -2, 2}, PlotPoints -> 100]


ap2 = ArrayPlot[matrix[f2][10, 100], Mesh -> None,
DataReversed -> True, DataRange -> {{-5, 5}, {-5, 5}},
ColorRules -> {1 -> Red, 0 -> White}];
Show[ap2, rp2, PlotRange -> {{-2, 2}, {-2, 2}}]