Why are there $\frac{(A+1)(A+2)(B+1)}{2}$ triangles in this grid? Suppose we are to find the number of triangles that exist from the given figure 
I found one solution that says we let $A$ equal the number of internal lines from the top vertex, $B$ equal the number of internal lines parallel to the base, using the formula below to find the number of $N$ triangles
$$N=\frac{(A+1)(A+2)(B+1)}{2}$$
With $A$ equal to 2 and $B$ equal to 3, we get $N=24$ triangles.
But can somebody explain why this formula works? How exactly do I derive this? 
 A: A triangle inside the figure has one of its sides being one of the $B+1$ horizontal lines, and the other two sides are two of the $A+2$ slant lines. So the total number of ways of forming a triangle is $\displaystyle {A+2 \choose 2} \times {B+1 \choose 1}$.
A: If we let $x$ to be the number of lines from the top vertex and $y$ to be the number of lines parallel to the base including the base, then we have $x = A+2$ and $y = B+1$. We keep this.
Now, think about how can we construct a triangle using these lines. First, we need a base, which we can choose from $y$ lines. Then, we need two other lines to construct a triangle but these two lines should intersect at one point (which is top vertex in this case). Therefore, we can actually choose $2$ lines from $x$ lines since all of these $x$ lines intersect at top vertex. So we can choose these $2$ lines with $\binom{x}{2} = \frac{x(x-1)}{2}$. So, in total, we can construct $\frac{x(x-1)y}{2}$ different triangles. Now, use $x = A+2$, $y = B+1$.
