How to know if a segment is completely included between two lines? I have three segments (not necessarily parralel):


*

*blue $((ax1, ay1), (ax2, ay2))$

*green$((bx1, by1), (bx2, by2))$

*red $((cx1, cy1), (cx2, cy2))$


and a $margin$ value which is the width of the sky blue band in the sketch bellow (with infinite length and always centered to the blue segment).

Is there a way to know if a segment is completely in the sky blue band knowing the coordinates of each segment and the value of the margin ?

If both endpoints are within the band, the segment is completely within the band.
The band is $2 h$ wide, and centered on a line passing through points $(x_1, y_1)$ and $(x_2, y_2)$.
(Note that I am using $(x_1,y_1)$ instead of $(ax1, ay1)$, and $(x_2, y_2)$ instead of $(ax2, ay2)$, and $h = {margin}/2$, because I find it clearer this way.)
Therefore, point $(x,y)$ is within the band if and only if its distance from the line passing through points $(x_1, y_1)$ and $(x_2, y_2)$ is at most $h$. 
Point-line distance is fortunately easy to calculate:
$$d = \frac{\left\lvert (x_2-x_1)(y_1-y) - (y_2-y_1)(x_1-x)\right\rvert}{\sqrt{(x_2-x_1)^2 + (y_2-y_1)^2}}$$
Thus, if both endpoints of a segment fulfill $2 d \le margin$ (or, $d \le margin/2$, or $d \le h$), the segment is completely within the band.
