I am trying to determine whether or not any part of a line segment is located within a square box. I have the coordinates of the line segment end points and the corners of the square box. This problem is easy for the case where one or both end points are located in the box, but I don't know what to do when the line crosses the box but both end points are located outside the box. This problem is in 2D. Anyone have any thoughts? Thanks in advance. Edited to add: This is not homework. I'm working on a PhD in a petroleum engineering related field. I am actually trying to determine the fractal dimension of fractures in rock (in 2D) and for this part I am using the box counting method. So, I'm trying to figure out if the line (the fracture) is located in the box.