Show there is a homeomorphism between a line segment and the unit interval Given a line segment defined as 
$$L = \{p + \lambda(q - p) \; | \; 0 \leq \lambda \leq 1\}
$$ with $p,q \in \mathbb{R}^2$, it seems obvious that $L$ is homeomorphic to the unit interval $[0,1]$ (project the line segment to the $x$-axis and shrink/expand it). However I'm not quite sure how to define the homeomorphism. I did it the other way around, leaving me with:
$$[0,1] \rightarrow \mathbb{R}^2,\;\;\lambda \mapsto p+\lambda(q-p)$$ with $\lambda \in [0,1]$. We have for $\lambda=0$ that  $0 \mapsto p$, which is the first endpoint of the segment, and for $\lambda = 1$ that $1 \mapsto p+q-p =q$ which is the second endpoint of the segment. The function is also continous. 
How do I define the inverse map $L \rightarrow [0,1]$?  
 A: If $p \ne q$ you can map $p + \lambda(q-p)$ to $\lambda$.
Edit: To answer all of your question, projection to the $x$-axis actually does not work for all $L$: Suppose $p = (0, 0)$ and $q = (0, 1)$. Then projecting to the $x$-axis yields just a single point. Surely, single points are not homeomorphic to lines (e.g., by a cardinality argument).
A: You don't want to define a homeomorphism with codomain $[0,1]$ whose domain is all of $\mathbb R^2$. 
You only want to define a homeomorphism with codomain $[0,1]$ whose domain is the line segment $L$ itself. And the formula for that homeomorphism is simply
$$f(p + \lambda(q-p)) = \lambda
$$
This is is well-defined (as long as $p \ne q$, which is a missing hypothesis of your question). Notice that this is the inverse function of the homeomorphism you defined in your question, and that inverse functions of homeomorphisms are also homeomorphisms (by the very definition of homeomorphism, which of course needs to be verified for the homeomorphism you defined in your question). 
