I think this is a very strange way to partition a matrix, however if it must be this way then I would let $(x,y)$ be the random point, determine the angle $\theta = atan2(y,x)$ that this point makes from the positive $x$ axis, and use that to determine which section it is in. This is a natural way considering that your partitioning is defined by angles about the origin.
You've drawn your particular problem with the first region starting at $\frac{3 \pi}{4}$. Following that, the solution for $n$ sections is as follows:
Start with calculating
$$\theta = \text{atan2}(x,y)$$ Then your answer is $$ \left\lceil \frac{\theta + \frac{\pi}{4}}{\frac{2 \pi}{n}} \right\rceil $$ This will give you the secion that your point is in with the first being $1$. If you want to start with the first being $0$, then you use floor instead of cieling.