# Possible number of line segments in a square grid

My problem is:

"How many possible line segments can be formed from an $$n \times n$$ square grid?"

For example by manual counting, if $$n = 1$$, then the number of line segments $$= 0$$; if $$n = 2$$, then the number of line segments $$= 6$$; and if $$n = 3$$, then the number of line segments $$= 36$$. All I can think of is the formula for finding all possible line segments where all points are noncollinear, that is $$\frac{n(n -1)}{2}$$, but how about a square grid whose intersection of horizontal and vertical line forms a point? How many possible line segments can be formed from such square?

• This tutorial explains how to typeset mathematics on this site. – N. F. Taussig Mar 29 at 14:08
• I do not follow. In the $3 \times 3$ case, you have already counted line segments that cross through the center point. – N. F. Taussig Mar 29 at 14:10
• No sir, i only count line segments defined by any 2 points on the square grid...but line segments that starts from opposite ends of the square that cross the center is not counted... – rosa Mar 29 at 14:19
• I only get 28 for 3 points across – Roddy MacPhee Mar 29 at 16:40
• I got 28 by not counting those line segments crossing another point/s I misunderstood... so if p = 1, l = 0, p = 2, l = 6, if p = 3 l = 28... is there any pattern evident? Im suck at combinatorics thats why I tried manual counting then derive formula algebraically... – rosa Mar 30 at 10:55