Where does this formula come from? As I was reading the papper "A method for registration of 3-d shapes", I came across the following passage. I don't quite understand the formula mentioned here. Could someone please give me some tips? I would be very grateful!

Let $\ell$ be the line segment connecting the two points $r_1$ and $r_2$. The distance between the point $p$ and the line segment $\ell$ is
$$d(p,\ell) = \min_{u+v=1}\lVert u·r_1 + v·r_2 - p\rVert.$$

 A: The idea is this:
The segment connecting the points $r_1$ and $r_2$ is also the set of all convex combinations of these vectors. Namely
$$\text{Segment}_{r_1,r_2} = \{u\cdot r_1 + v\cdot r_2 : u+v=1\}$$
Then we want to define the distance between a point $p$ to the segment. The key is that we have a natural definition for the distance between two points. If $x,y$ are two points then their distance is given by $d(x,y) = \|x-y\|$. Then the most natural way to define the distance between a point and a segment is to define it to be the distance between this point to the closest element in the segment. Namely
$$d(p,\text{Segment}_{r_1,r_2}) = \min \{d(p,x) : x\in \text{Segment}_{r_1,r_2}\} = \min \{\|x-p\| : x=u\cdot r_1 +v\cdot r_2, u+v=1\}$$
A: Well we can describe the line segment $\ell$ as the set
$$\ell=\{r_1+t(r_2-r_1):t\in[0,1]\}=\{(1-t)r_1+tr_2:t\in[0,1]\}.$$
This means that if $x\in\ell$, then there is some $t\in[0,1]$ such that
$$x=(1-t)r_1+tr_2.$$
If we now set $u=1-t$ and $v=t$, then this becomes
$$x=ur_1+vr_2.$$
Clearly $u+v=1$, and they uniquely define $x$, we just need to also require that $u,v\geq0$. Since this representation is thus unique, we have that
$$d(p,\ell)=\min_{x\in\ell}\lVert x-p\rVert=\min_{\substack{u+v=1\\u,v\geq0}}\lVert ur_1+vr_2-p\rVert,$$
which is the formula you had.
