How Do You Determine if a Line Segment Intersects a Square in 2D Geometry?

  • Context: Graduate 
  • Thread starter Thread starter eniven
  • Start date Start date
  • Tags Tags
    Programming
Click For Summary

Discussion Overview

The discussion revolves around determining whether a line segment intersects a square in 2D geometry. Participants explore various methods and considerations for identifying intersections, particularly when both endpoints of the line segment are outside the square.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant notes that if the line segment is partially inside the square, it must intersect at least one of the four sides of the square.
  • Another suggests that connecting the endpoints of the line segment can help determine if it crosses the sides of the box.
  • A different approach involves using inequalities derived from the line equation to assess whether points are inside or outside the square.
  • Some participants express uncertainty about how to handle cases where neither endpoint is inside the square but the line crosses it.

Areas of Agreement / Disagreement

Participants present multiple competing views on how to determine intersections, and the discussion remains unresolved regarding the best approach, particularly for cases where both endpoints are outside the square.

Contextual Notes

There are limitations in the discussion regarding the assumptions made about the geometry of the line and square, as well as the mathematical steps required to determine intersections.

eniven
Messages
3
Reaction score
0
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.
 
Last edited:
Mathematics news on Phys.org
There is an equation that defines the line segment, right?

There are equations that define the four line segments that define the square, right?

If the line segent is partially inside the square, it must intersect at least one of the four line segments that make up the square, right?

If it intersects none of them, it doesn't cross the square.
 
I'm not sure if I got the question right, but if you're asking if any part of a line segment is in a box, then you should be able to connect the endpoints of the line and see if it crosses the sides of the box (if it does, then part of the line segment is in the box).
 
Thanks guys! I feel like a bit of a doofus for not thinking of that! :redface:
 
Another way to do it is this: Every straight line determines a specific inequality. That is, if the line is given by ax+ by+ c= 0 then every point on one side of the line satisfies ax+ by+ c> 0 and every point on the other side satisfies ax+ by+ c< 0. Given a single point inside the box, you can determine what inequalities every point inside the box must satisfy and use that to determine whether the endpoints of the line segment are inside the box or not. That should be simpler than solving equations to determine where or if the given line segment intersects a side.
 
HallsofIvy said:
Another way to do it is this: Every straight line determines a specific inequality. That is, if the line is given by ax+ by+ c= 0 then every point on one side of the line satisfies ax+ by+ c> 0 and every point on the other side satisfies ax+ by+ c< 0. Given a single point inside the box, you can determine what inequalities every point inside the box must satisfy and use that to determine whether the endpoints of the line segment are inside the box or not. That should be simpler than solving equations to determine where or if the given line segment intersects a side.

Hmm, that's clever, but what about the case where neither end point of the line are inside the square yet the line crosses the square?
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 17 ·
Replies
17
Views
3K
Replies
1
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 20 ·
Replies
20
Views
2K
Replies
3
Views
3K
  • · Replies 40 ·
2
Replies
40
Views
5K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K