Example 4 As shown in Figure 2, given a triangular array of $\frac{n(n+1)}{2}$ points, let the number of all equilateral triangles formed by three points in the array be $f(n)$. Find $f(n)$

Figure 2 expression. ${ }^{\text {[3] }}$
Let $f(i)(i=1,2, \cdots, n)$ denote the number of all equilateral triangles formed by the points in the first $i$ rows. It is known that
$$
f(1)=0, f(2)=1, f(3)=5 \text {. }
$$

Next, we seek the relationship between $f(n)$ and $f(n-1)$.
Clearly, $f(n)$ equals $f(n-1)$ plus the number of all equilateral triangles that have one or two vertices in the $n$-th row. Among these, the equilateral triangles with two vertices in the $n$-th row are called Class I, and there are $\mathrm{C}_{n}^{2}$ of them.

Next, we consider the equilateral triangles that have only one vertex in the $n$-th row, which we call Class II, and study their number.

Suppose $\triangle A B C$ is a Class II triangle, with vertex $A$ in the $n$-th row. Draw lines through vertices $B$ and $C$ parallel to the boundaries of the triangular grid, intersecting the $n$-th row at points $P$ and $Q$. Thus, $\triangle A B C$ corresponds uniquely to a sequence of three points $(P, A, Q)$.

Conversely, for any sequence of three points $(P, A, Q)$ on the $n$-th row, construct an equilateral triangle with vertices $P$ and $Q$ within the triangular grid, and then construct an inscribed equilateral $\triangle A B C$ with vertex $A$. Clearly, such a triangle is uniquely determined.

Thus, a one-to-one correspondence is established between Class II equilateral triangles and sequences of three points.
Hence, there are $\mathrm{C}_{n}^{3}$ Class II equilateral triangles.
Therefore, $f(n)=f(n-1)+\mathrm{C}_{n}^{2}+\mathrm{C}_{n}^{3}$.
Summing the recurrence relation for $n$ ranging from $2$ to $n$, and given $f(1)=0$, we get
$$
\begin{array}{l}
f(n)=\sum_{i=2}^{n}\left(\mathrm{C}_{i}^{2}+\mathrm{C}_{i}^{3}\right)=\frac{1}{6} \sum_{i=2}^{n}\left(i^{3}-i\right) \\
=\frac{1}{6}\left(1^{3}+2^{3}+\cdots+n^{3}\right)-\frac{1}{6}(1+2+\cdots+n) \\
=\frac{1}{6} \times \frac{1}{4} n^{2}(n+1)^{2}-\frac{1}{6} \times \frac{1}{2} n(n+1) \\
=\frac{(n-1) n(n+1)(n+2)}{24} .
\end{array}
$$

The principle of correspondence involves transforming the counting of elements in one set to the counting of elements in another set, provided that the two sets are in a one-to-one correspondence under some mapping. In solving combinatorial geometric counting problems, appropriately considering the principle of correspondence often simplifies the solution process, achieving twice the result with half the effort.