Minimization of a piecewise affine function of $2$ variables How does one minimize the following function?
$$f(x,y) = |kx + ly + c|$$
where $x,y \in \mathbb N$.
 A: What is going on?
Let us first look at the real case:


We see that $f(x,y) = \lvert (k, l) (x,y)^\top + c \rvert$ results in a $V$ shaped surface. The reason is the "case distinction" of the absolute value function.
The valley line (the red line at $z=0$) is
$$
\frac{1}{\sqrt{k^2 + l^2}} (k, l) (x,y)^\top = \frac{-c}{\sqrt{k^2 + l^2}} = d
$$
where $(1/\sqrt{k^2 + l^2}) (k,l)^\top$ is a unit normal vector to the valley line (see the vector on the unit circle in the left graph) and $\lvert d \rvert$ is the distance to the origin (see the radius of the green circle and green sphere).
Discrete case:
For the discrete case we need to determine the intersections of $f$ with the grid $\mathbb{Z}^3$.
It should run down into coming up with the two planes that the $V$ is part of, stating the linear Diophantine equation there, and going for the smallest positive solution each, finally picking the smallest $z$-value of both cases.
Determining the planes:
The two linear Diophantine equations in three variables are 
$$
k x + l y - z = -c \\
k x + l y + z = -c 
$$
where the part intersecting with $f$ is characterized by $z \ge 0$.
Examples on how to solve such equations are given here and here.
