Per the title, I'm seeking the definition of a function $f(n, m)$ which evaluates to the number of lines made from exactly n points which can be placed on a 2 dimensional square grid of size $m \times m$.

As an aside, I actually only need to know the partial function for $n = 3$, however since I see that [$n = 2$ has been answered][1] already, I figured I might as well generalize the question. If it turns out that answering the general form of this question is quite difficult, I will edit to only include $n = 3$.


  [1]: http://mathoverflow.net/q/2806/92343