TITLE: If $f:\mathbb R^2 \to \mathbb R$ continuous on straight lines and $f(\text{compact})= \text{compact}$, then $f$ continuous?
QUESTION [10 upvotes]: Let $f:\mathbb{R}^2$ $\rightarrow$ $\mathbb{R}$ be a map such that

$f$ is continuous over all segments (namely, for all $a,b$ $\in$ $\mathbb{R}^2$, $t$ $\mapsto$ $f(at+b)$ is continuous), and

If $K$ $\subset$ $\mathbb{R}^2$ is compact, then its image $f(K)$ is compact.


Then $f$ is continuous.
I tried to prove this, but I could not do it. Can you give me a hint?

REPLY [7 votes]: Yes. Assume otherwise. WLOG, $f(0)=0$ is discontinuous and find $x_n\to 0$ such that $f(x_n)$ does not converge to zero. If $f(x_n)$ is unbounded, then the image of the compact set $\{0\}\cup \{x_n\}$ is not compact. So $f(x_n)$ is bounded. Choose a subsequence $x_n'$ such that $f(x_n')$ converges to $c\neq 0$. If $c\neq f(x_n')$ for each $n$, we are done, because $\{0\}\cup \{x_n'\}$ is compact and the image is not.
Now for each $n$ where $c=f(x_n')$, we use the continuity on the line $\{tx_n'\,| t\in R\}$ and find a number $x_n'' = t_n x_n'$ for some $0< t_n < 1$ so that $f(x_n'')=c(1 - \frac{1}{n})$. If $f(x_n')\neq c$, we leave $x_n'':=x_n'$. So then $f(x_n'')$ still converges to $c$, $x_n''$ still converges to $0$, but the image of $\{0\}\cup \{x_n''\}$ is not compact.