the area that a part of an ellipse consumes in a square of a discrete grid Think about a discrete grid of unit 1, which means the grid consists of infinite number of squares whose area is 1. You can assign a coordinate to each square and one of them will have the coordinate (0, 0). The other squares will be assigned a coordinate in a way analogous to the 2-dimensional cartesian coordinate system. You can also draw 0-dimensional dots on this grid and those dots will have coordinates of real numbers. A dot with integer coordinates are in the exact center of a square. So a dot (1.5, 3) will be on the center of the edge between square (1, 3) and (2, 3).
On this grid, we want to draw an ellipse whose center is a dot ($x$, $y$) and whose horizontal and vertical radius is $a$ and $b$ respectively. Some squares on the grid will be completely full with the ellipse, some others will be partly full, and the left ones will be empty. Let us pick an arbitrary square ($p$, $q$), and we want to know the area that the ellipse consumes in this square. This would be a function of 6 inputs: $x$, $y$ for the coordinate of the center of the ellipse; $a$, $b$ for the horizontal and vertical radius of the ellipse; and $p$, $q$ for the coordinate of the square in our interest.
Can you help me bring out an expression for this function? Can it be in a single line elementary algebraic expression, or would it be some kind of an algorithm maybe?
 A: The area can be computed using methodology in this answer which compute the area of intersection between a square and a circle. 
Let $\mathcal{E}$ be an axis-aligned ellipse centered at $(x,y)$ with semi-axes $a$ and $b$. Let $\mathcal{S}$ be the unit square centered at $(p,q)$. Define
$$\begin{cases}
u_\pm &= \frac{p-x \pm \frac12}{a}\\
v_\pm &= \frac{q-y \pm \frac12}{b}
\end{cases}
\quad\text{ and }\quad
h(u) = \begin{cases}
\pi,& u \in [1,\infty)\\
\pi - \cos^{-1}(u) + u\sqrt{1-u^2},& u \in (-1,1)\\
0,& u \in (-\infty, -1]
\end{cases}$$
The area of $\mathcal{E}\cap\mathcal{S}$ is given by the formula
$$\verb/Area/(\mathcal{E}\cap\mathcal{S}) = \pi ab\left[\Delta(u_+,v_+)-\Delta(u_+,v_-)-\Delta(u_-,v_+)+\Delta(u_-,v_-)\right]$$
where $\Delta(u,v)$ can be computed using following table
$$\begin{array}{rcc}
\hline
 \verb/Condition/ && \Delta(u,v)\\
\hline
u^2 + v^2 \le 1 && \frac{h(u) + h(v)}{2} - \frac{\pi}{4} + uv\\
u \le -1 \vee v \le -1 && 0\\
u \ge  1 \wedge v \ge 1 && \pi\\
u \ge  1 && h(v)\\
v \ge  1 && h(u)\\
u \ge  0 \wedge v \ge 0 && h(u) + h(v) - \pi\\
u \ge  0 \wedge v \le 0 && h(v)\\
u \le  0 \wedge v \ge 0 && h(u)\\
\verb/otherwise/ && 0\\
\hline
\end{array}$$
One look at the conditions in this table one by one. If $(u,v)$ satisfy a condition, then $\Delta(u,v)$ will be given by the expression at the right. If not, move to next condition. 
For completeness, following is a picture from aforementioned answer which illustrate in which range of $(u,v)$, one should use which formula for $\Delta(u,v)$.

