# condition for a set to be compact and convex

Is it true that a set in, say, $n$-dimensional Euclidean space is compact and convex iff its intersection with any line is empty, a single point, or a closed line segment?

-

Yes. "Only if" is easy, so suppose the intersection of $K$ with any line is empty, a single point, or a closed line segment. Then $K$ is convex: if $x \in K$ and $y \in K$, consider the intersection of $K$ with the line through $x$ and $y$.

To show that $K$ is closed: we may assume wlog that $K$ has interior (otherwise embed it in ${\mathbb R}^k$ for some $k < n$), and (by translation) that $0$ is in that interior. If $p \in \overline{K} \backslash K$, I claim $tp \in K$ for $0 \le t < 1$, which implies $p \in K$. Namely, suppose $B_\delta \subseteq K$, where $B_\delta$ is the open ball of radius $\delta$ centred at $0$. Then if $p' \in K$ with $\|p' - p\| < \eta = \delta (1 - t)/t$, we have $t p \in t p' + B_{t \eta} = t p' + (1-t) B_\delta \subseteq K$.

Finally, to show that $K$ is bounded: suppose $x_n \in K$ with $\|x_n\| \ge n$. Then $y_n = x_n/\|x_n\| \in K$ with $\|y_n\| = 1$. By passing to a subsequence, we may assume $y_n \to y$, which is in $K$ because $K$ is closed. Now for any positive integer $m$, $m y_n \in K$ for all sufficiently large $n$, and again since $K$ is closed, $m y = \lim_{n \to \infty} m y_n \in K$. So the intersection of $K$ with the line through $0$ and $y$ is unbounded, which is a contradiction.

-
Convex sets are connected. Note that the connected subsets of $\mathbb{R}$ are: $\emptyset$, singletons, intervals, rays, and the whole line. The intersection of two convex sets is convex (same holds replacing "convex" with any of "compact," "closed," "bounded," or "connected"). Noting that a (half-)open line segment is not closed, that rays (and whole lines) are not bounded, it follows that if a set in $\mathbb{R}^n$ is convex and compact (so closed and bounded), then since lines are convex and connected their intersection with the convex, compact set will necessarily be one of the three desired set types.
It is clear that if $A\subseteq\mathbb{R}^n$ fails to be convex, then there is a line whose intersection with $A$ fails to be connected. If $A$ is convex but fails to be bounded, then it contains a closed ray (this shouldn't be too tricky to justify). Suppose $A$ is convex and bounded but fails to be closed, so there is some limit point $x$ of $A$ with $x\notin A$. Then at least one of the following should hold: (i) there is some hyperplane $P$ of dimension $n-1$ such that $A\cap P=\emptyset$ and $x\in P$ or (ii) every hyperplane $P$ of dimension $n-1$ with $x\in P$ contains a line $L$ whose intersection with $A$ it a (half-)open line segment. Since "closed and bounded=compact" in $\mathbb{R}^n$, then in case (ii), we're done, and in case (i), the line through $x$ normal to the plane $P$ will have its intersection with $A$ is a (half-)open line segment, and again we're done. Thus, we see that if $A$ has the property that for every line $L$, $A\cap L$ is either empty, a singleton, or a closed line segment, then $A$ is convex and compact. (Play with it a bit to justify the claims made in this paragraph. If you get stuck, make a comment, and I'll be on later to help you out.)