# About convexity of a set in $\mathbb{R}^n$

Can we say that a set $$E\subset \mathbb{R}^n$$ is convex iff $$E\cap L$$ is contractible for every real affine line $$L$$ in $$\mathbb{R}^n$$?

I know that $$E\subset \mathbb{R}^n$$ is convex iff $$E\cap L$$ is convex for every real affine line $$L$$ in $$\mathbb{R}^n$$. And a convex set is contractible.

Also if we consider $$E\subset \mathbb{R}^n\subset \mathbb{C}^n$$ , then is $$E$$ convex if and only if $$E\cap L$$ is contractible for every complex affine line $$L$$ in $$\mathbb{C}^n$$?

Strictly speaking this is not true since $$\emptyset$$ is not contractible. So let us interpret the condition in the sense that for every real affine line $$L$$ in $$\mathbb{R}^n$$, the set $$E\cap L$$ is either empty or contractible.
You know that $$E$$ is convex iff $$E\cap L$$ is convex for every real affine line $$L$$ in $$\mathbb{R}^n$$. Thus your first question is equivalent to showing that a subset $$A \subset \mathbb R$$ is convex iff it is contractible.
Clearly nonempty convex sets are contractible. Now assume that $$A$$ is not convex. This means that there exist $$x,y \in A$$ such that $$z_t = tx + (1-t)y \notin A$$ for some $$t \in [0,1]$$. W.l.o.g. we may assume that $$x \le y$$. It is impossible that $$x = y$$ because then $$z_t = x$$ for all $$t \in [0,1]$$. Thus $$x < y$$. Hence $$A$$ is not connected because $$A \cap (-\infty, z_t)$$ and $$A \cap (z_t,\infty)$$ form a partition of $$A$$ in disjoint nonempty open sets. But a non-connected set is not contractible.