Math / Programming Problem

In summary, the question at hand is how to determine if any part of a given line segment is located within a square box. The line segment has endpoints with coordinates and the square box has corners with coordinates. It is easy to determine if one or both endpoints are within the box, but the problem arises when the line crosses the box with both endpoints outside. This is a 2D problem and the desired outcome is to determine the fractal dimension of fractures in rock using the box counting method. One approach is to connect the endpoints and see if it crosses any sides of the box, but another option is to use the inequalities determined by the line to determine if the endpoints are inside the box. However, this may not account for the case
  • #1
eniven
3
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
  • #2
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.
 
  • #3
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).
 
  • #4
Thanks guys! I feel like a bit of a doofus for not thinking of that! :redface:
 
  • #5
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.
 
  • #6
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?
 

1. What is the difference between math and programming?

Math is a branch of science that deals with numbers, quantities, and space. It is used to solve problems and analyze data. Programming, on the other hand, is the process of creating instructions for a computer to follow in order to complete a specific task. While math is a tool used in programming, programming involves much more than just numbers and equations.

2. Why is it important to have strong math skills for programming?

Math and programming are closely related, as programming often involves solving complex problems and making calculations. Strong math skills can help in understanding algorithms, writing efficient code, and debugging errors. Additionally, programming often involves working with data, and having a good understanding of math concepts like statistics and algebra is crucial for data analysis and manipulation.

3. How can I improve my problem-solving skills in math and programming?

Practice is key in improving problem-solving skills in both math and programming. Solving a variety of problems and challenges can help you develop critical thinking and analytical skills. Additionally, seeking feedback and learning from others can also help you improve your problem-solving abilities. It is also important to have a strong foundation in the fundamental concepts and techniques of math and programming.

4. What are some common mistakes to avoid when solving math/programming problems?

Some common mistakes to avoid when solving math or programming problems include not understanding the problem fully, not checking for errors, and not using efficient techniques or algorithms. It is also important to avoid jumping to conclusions or making assumptions without proper evidence. Additionally, it is crucial to check your work and ensure that your solution is logical and accurate.

5. How can I prepare for math/programming problem-solving interviews?

To prepare for math/programming problem-solving interviews, it is important to practice solving a variety of problems and challenges. You can also review fundamental concepts and techniques, as well as common algorithms and data structures. It can also be helpful to research the company and the specific role you are interviewing for, as this can give you an idea of the types of problems you may encounter during the interview.

Similar threads

  • General Math
Replies
1
Views
999
Replies
29
Views
1K
Replies
5
Views
1K
  • General Math
Replies
5
Views
2K
  • General Math
Replies
1
Views
1K
Replies
1
Views
1K
Replies
5
Views
478
  • General Math
Replies
8
Views
2K
Replies
4
Views
632
Replies
1
Views
1K
Back
Top