Algorithm for detection of overlaping between vectors
If you have two line segments and you want to know if they intersect, see https://en.wikipedia.org/wiki/Line_intersection and https://en.wikipedia.org/wiki/Line_segment_intersection.

For next time, I'd expect you to do more research on your own.  See especially "computational geometry", e.g., a textbook that covers that area.