I have a piecewise linear function $f: \mathbb R^2 \to \mathbb R$ and have the values of three (linearly independent) points $(x_i,y_i)$ on such a piece:
$$z_i = f(x_i,y_i) \quad i=1,2,3$$
How can I find the gradient $\nabla f$ on this piece?
Mi first idea was going via 3d normal, but I was not sure about the scaling and projection back into $\mathbb R^2$.
On that piece, $f(x, y) = a x + b y + c$, since $f$ is linear. (This piece would also have $\nabla f = \begin{pmatrix}a\\b\end{pmatrix}$).
Your equations $z_i = f(x_i, y_i)$ give three simultaneous equations in three variables, which can be solved for the values of $a$ and $b$, giving the gradient.
In particular, you can write $$\begin{pmatrix}z_1 \\ z_2 \\ z_3\end{pmatrix} = \begin{pmatrix}x_1 & y_1 & 1 \\ x_2 & y_2 & 1 \\ x_3 & y_3 & 1\end{pmatrix}\begin{pmatrix}a\\b\\c\end{pmatrix},$$ and invert the $3\times3$ matrix to solve for $a$,$b$,$c$.