In this solution points

and

may happen to be outside the intervals

and

.
In this case both

and

will coincide with the point

(happens if the point

was on or below the line

). In this case point

will be the intersection between lines

and

. The rest is the same.