Consider the set $\mathcal S \subseteq \mathbb{R}^n$
$\mathcal S = \{x|f(x)\le c\}$
where $x\in\mathbb{R}^n$, $c\in\mathbb{R}$, and $f:\mathbb{R}^n\to\mathbb{R}$ is convex (so $\mathcal S$ is a convex set). Say I have a point $\hat x\in\mathbb{R}^n$ that is not in $\mathcal S$. I want to determine a vector $z$ such that $\hat x - z \in \mathcal S$.
I was thinking that the shortest distance vector, with respect to the Euclidean norm in $\mathbb{R}^n$, from $\hat x$ to $\mathcal S$ would yield the "best" $z$ vector, but I'm not sure how to obtain the shortest distance in $n$-dimensions.
I know in two dimensions we just take the derivative of $D(x) = \sqrt{(a-x)^2+(b-f(x))^2}$ and equate it to zero to determine the shortest distance from $(a,b)$ to the curve $y=f(x)$, but how does this generalize to $n$-dimensions?