The formula you are looking for is Lagrange Basis Polynomials. Essentially, each share consists of two values, an x coordinate and an y coordinate. The x coordinate might, depending on your specific needs, be implicitly determined by context, such as a preexisting identifier for the entity holding the share. The only requirement is that it is non-zero and unique. The y coordinate is calculated as the value of the polynomial (with random coefficients and a degree equal to the threshold parameter) in the x coordinate.
Hence, in pseudo code, in order to generate $n$ shares such that at least $m+1$ shares are required to regenerate the secret, and presuming you work in a $\mathbb Z_p$ field, do the following:
$Input: $ Parameters $n, m$. A large prime $p$. Secret $s$, represented as an element in $\mathbb Z_p$. Coordinates $x_0,...,x_{n-1}$.
$Setup:$
- $c_0 = s$
- For $i$ from 1 to $m$ do
- $c_i \leftarrow_{Uniform} \mathbb Z_p^*$
- For $j$ from 0 to $n-1$ do
- $y_j = \Sigma_{i=0}^mc_ix_j^i$
You regenerate the secret $s$ from $k$ shares, such that $k \gt m$, by implementing the Lagrange Interpolation Polynomial $L(x)$ using the $x_j,y_j$ pairs you got access to, and calculating $s' = L(0)$.
As per your question, if $m = 2$ and $k = 3$ (presuming that $k = n$ for simplicity), the formula for $L(x)$ becomes:
$L(x) = y_0\frac{(x-x_1)(x-x_2)}{(x_0-x_1)(x_0-x_2)} + y_1\frac{(x-x_0)(x-x_2)}{(x_1-x_0)(x_1-x_2)} + y_2\frac{(x-x_0)(x-x_1)}{(x_2-x_0)(x_2-x_1)}$