# Expressing a convex Polytope as a sublevel set of a function

Given an n-dimensional polytope $P$ in $\mathbb R^n$, Given as a convex hull of a finite set of points, $S$ I would like to construct an expliict formula for a function $f\colon \mathbb R^n \to \mathbb R$ such that $P=\left\{x\in\mathbb R^n \Big|\ f(x) \le 1\right\}$ Is there any nice known closed formula? It seems that there should be one in existance, as everything is piecewise linear.

Moreover, I would like to ask the same question in the case P is given as intersections of half planes (hence, the data I have are normal vectors to the plane and distance from the origin)

Thanks

If it's given as the intersection of half-spaces $\{x \mid v_i \cdot x \le d_i\}$, then you can take $f(x) = \max_i ( v_i \cdot x - d_i)$ and have $P = \{x \mid f(x) \le 0\}$.