Understanding homotopy equivalence in a special case I'm beginning to learn algebraic topology from Hatcher, and I'm trying to get an intuitive grasp on homotopy equivalence. Hatcher says these two shapes are homotopy equivalent:

Let's call the left one A and the right one B. I can easily see visually how to "stretch" A to get B, but I'm having trouble understanding how to apply the actual, formal definition of homotopy equivalence.
Specifically, we need continuous functions $f : A\to B$ and $g : B\to A$ such that $fg$ is homotopic to $id_B$ and $gf$ is homotopic to $id_A$. But I can't really see how to do this. For $g$, we can map the whole vertical bar of $B$ (including the endpoints) to the point at the center of $A$, and the other parts of $B$ besides the vertical bar to the round parts of $A$ in the obvious way. This is continuous. But what can we do for a continuous $f$, such that the compositions $fg$ and $gf$ are homotopic to the identity maps?
 A: Let $S(p)$ denote the plane circle with radius $1$  and center $p \in \mathbb R^2$ and $D = \{0\} \times [-1,1]$. Let $S_l(p)$ and $S_r(p)$ denoet the left and right closed halfcircle of $S(p)$. Let $p^- = (-1,0), p^+ = (1,0)$ and $p^0 = (0,0)$.
Then
$$A = S(p^-) \cup S(p^+) , B = S(p^0) \cup D .$$
Define $f : A \to B$ by projecting $S_r(p^-)$ and $S_l(p^+)$ horizontally to $D$ and by translating $S_l(p^-)$ horizontally to $S_l(p^0)$ and translating $S_r(p^+)$ horizontally to $S_r(p^0)$.
Define $g : B \to A$ by contracting $D$ to $p^0$ and mapping $S_l(p^0)$ in the obvious way to $S(p^-)$ and $S_r(p^0)$ to $S(p^+)$.
The explicit construction of homotopies $gf \simeq id_A$ and $fg \simeq id_B$ is somewhat tedious, but I am sure you can see how that works. The essence is to understand that the identity $id_S$ on a circle $S$ is homotopic to map $\phi : S \to S$ contracting a closed half circle $H  \subset S$ to a point $h \in H$. This homotopy keeps $h$ fixed and "stretches" the open halfcircle $S \setminus H$ to $S \setminus \{h\}$.
