Thomae function -- points lying on the same line 
Plotted is $y=f(x)$ for $x\in[0,1]$, where $$f(x) =\begin{cases}\frac{1}{q}\quad\text{ if }x=\frac{p}{q}\text{, $p$, $q$ coprime ($q$ positive)} \\ 0\quad\text{ if $x$ is irrational}\end{cases}$$ I can see why horizontal lines appear, but what is the reason for all the other straight lines appearing?
 A: Let us assume that $\left(\frac{p}{q},\frac{1}{q}\right)$ and $\left(\frac{P}{Q},\frac{1}{Q}\right)$ are two distinct points on the graph of the popcorn function. Are there other points of the graph on the line joining them? Yes, iff
$$ \det\begin{pmatrix}1 & \frac{p}{q} & \frac{1}{q} \\ 1 & \frac{P}{Q} & \frac{1}{Q} \\  1 & \frac{u}{v} & \frac{1}{v} \\\end{pmatrix}=0 $$
has a non-trivial solution with $u,v\in\mathbb{N}^+$ and $\gcd(u,v)=1$. This constraint is equivalent to
$$ \det\begin{pmatrix}1& p & q\\ 1 & P & Q \\ 1& u & v \end{pmatrix}=0$$
which depends on the number of primitive (meaning: with coprime coordinates) lattice points on the line joining $(p,q)$ with $(P,Q)$. So, roughly speaking, the presence of many lines in $\mathbb{N}\times\mathbb{N}$ implies the presence of many collinear points in the graph of the popcorn function. For instance, the line $(1,2)-(2,3)-(3,4)-(4,5)-\ldots$ in $\mathbb{N}^2$ is associated to the line (the top right side) $\left(\frac{1}{2},\frac{1}{2}\right)-\left(\frac{2}{3},\frac{1}{3}\right)-\left(\frac{3}{4},\frac{1}{4}\right)-\left(\frac{4}{5},\frac{1}{5}\right)-\ldots$ in the graph of the popcorn function.
