Example 2 Let $f(n)$ denote the minimum number of distinct points in a planar point set $X$, such that for each $k=1$, $2, \cdots, n$, there exists a line in the plane that contains exactly $k$ points of $X$. Find $f(n)$.
Let $X_{n}$ be the set of points in the plane that satisfies the following condition: for every positive integer $k (1 \leqslant k \leqslant n)$, there exists a line $l_{k}$ in the plane such that $l_{k}$ contains exactly $k$ points of $X_{n}$. Now we estimate how large $\left|X_{n}\right|$ should be at least.

First, $l_{n}$ contains $n$ points of $X_{n}$; $l_{n-1}$ contains $n-1$ points of $X_{n}$, and at least $n-2$ of these points are not on $l_{n}$; $l_{n-2}$ contains $n-2$ points of $X_{n}$, and at least $n-4$ of these points are not on $l_{n}$ and $l_{n-1}$; and so on. Therefore, we have
$$
\left|X_{n}\right| \geqslant n+(n-2)+(n-4)+\cdots+\left(n-2\left[\frac{n}{2}\right]\right) .
$$

Let $g(n)=n+(n-2)+(n-4)+\cdots+\left(n-2\left[\frac{n}{2}\right]\right)$. Then, when $n=2 m$,
$$
g(n)=2 m+2(m-1)+2(m-2)+\cdots+2=m(m+1)=\frac{n(n+2)}{4} ;
$$

When $m=2 m-1$,
$$
g(n)=(2 m-1)+(2 m-3)+(2 m-5)+\cdots+1=m^{2}=\frac{(n+1)^{2}}{4} .
$$

Thus, $g(n)=\left[\frac{(n+1)^{2}}{4}\right]$.
Therefore, we have
$f(n)=\min \left\{\left|X_{n}\right| \mid X_{n}\right.$ satisfies the given condition $\} \geqslant g(n)$.
Conversely, we use mathematical induction to prove that for any positive integer $n$, there exists a set of points $X_{n}$ in the plane such that $\left|X_{n}\right|=$ $g(n)$, and for every $k (1 \leqslant k \leqslant n)$, there exists a line $l_{k}$ in the plane such that $l_{k}$ contains exactly $k$ points of $X_{n}$.
For $n=1$ and $n=2$, a set of points $X_{1}$ containing one point and a set of points $X_{2}$ containing 2 points clearly satisfy the requirements.
Assume that for $n=m$, there exists a set of points $X_{m}$ in the plane such that $\left|X_{m}\right|=g(m)=\left[\frac{(m+1)^{2}}{4}\right]$, and there exist lines $l_{k} (k=1,2, \cdots, m)$ such that $l_{k}$ contains exactly $k$ points of $X_{m}$. Take a line $l$ that is not parallel to any of $l_{1}, l_{2}, \cdots, l_{m}$, and the intersection point $P_{k}$ of $l$ and $l_{k}$ does not belong to $X_{m} (k=1,2, \cdots, m)$. Let $P_{m+1}, P_{m+2}$ be any two points on $l$ different from $P_{1}, P_{2}, \cdots, P_{m}$, and let $X_{m+2}=X_{m} \cup\left\{P_{1}, P_{2}, \cdots, P_{m+2}\right\}$. Then
$$
\begin{aligned}
\left|X_{m+2}\right| & =g(m)+(m+2)=(m+2)+m+(m-2)+\cdots+\left(m-2\left[\frac{m}{2}\right]\right) \\
& =(m+2)+m+(m-2)+\cdots+\left((m+2)-2\left[\frac{m+2}{2}\right]\right)=g(m+2) .
\end{aligned}
$$

Let $l^{\prime}_{k+1}=l_{k} (k=1,2, \cdots, m), l^{\prime}_{k+2}=l$, and draw any line $l^{\prime}_{1}$ that passes through one point of $X_{m+2}$. Then for any $k=1,2, \cdots, m+2$, there exists a line $l_{k}^{\prime}$ in the plane such that $l^{\prime}_{k}$ contains exactly $k$ points of $X_{m+2}$, completing the inductive proof.
In summary, we have $f(n)=g(n)=\left[\frac{(n+1)^{2}}{4}\right]$.