What is meant by gluing two metric spaces together? "Gluing" constructions are common in topology: by gluing two disks along their boundaries we get a sphere; by gluing a cylindical "handle" to a sphere we get a torus, and so forth. 
If the original spaces have a metric in addition to topology, when and how do these metrics carry over to the result of gluing? What are the compatibility conditions required for the glued space to have a metric of its own? 
 A: To perform the gluing, we need: 


*

*two metric spaces $X$ and $Y$

*a set $A\subset X$, this is the part of $X$ covered in glue

*an isometric embedding $f:A\to Y$, which is a way to put the glue-covered part of $X$ over $Y$. 


After we firmly press the spaces together and let them sit for a while, a point $x\in A$ becomes identical with the point $f(x)\in Y$. The resulting space can be described as the quotient $(X\sqcup Y)/(x\sim f(x))$. It is usually denoted $X\cup_A Y$. Its metric is the standard quotient metric; however, in this case the formula for quotient metric can be simplified to 
$$
\tilde d(p,q) = \begin{cases}
d_X(p, q) & \mbox{if } p, q \in X \\
d_Y(p, q) & \mbox{if } p, q \in Y \\
\inf_{a\in A} [d_X(p, a)+d_Y(q, f(a))] & \mbox{if } p \in X \mbox{ and } q \in Y \\
\inf_{a\in A} [d_Y(p, f(a)) + d_X(q, a)] & \mbox{if } p \in Y \mbox{ and } q \in X
\end{cases}
$$ 
A simple example to start with: $X=(-\infty,0]$, $A=\{0\}$, Y=$[0,\infty)$, $f(0)=0$. This means we glue two half-lines together at point $0$. The result is  $\mathbb R$ with the standard metric.
Another example:  glue two closed disks of the same radius along their boundaries. This means $A$ is the boundary of one disk, and $f(A)$ is the boundary of the other. The resulting space is homeomorphic to a sphere, though the metric on each disk is still flat. It's like a sphere that someone sat on. 
