The length of a line intersecting a rectangle - not just diagonal

In summary, the conversation discussed the possibility of finding the length of a line section within a rectangle using a simple linear equation and the extents of the rectangle. The solution may involve using conditional statements to determine if the line intersects with each side of the rectangle. The question was also raised if the problem could be simplified by only considering rectangles parallel to the x- and y-axes. The use of a mathematical expression was suggested, but it was acknowledged that multiple tests may be necessary due to the non-analytic-continuous nature of the problem.
  • #1
renucrew
6
0
Hi

Given a simple linear equation and the extents of a rectangle, is there a neat way of finding the length of the line section that is contained within the rectangle?

The only general method i can think of would involve a bunch of conditional statements to determine whether the line intersects each side of the rectangle.

 
Physics news on Phys.org
  • #2
renucrew said:
Hi

Given a simple linear equation and the extents of a rectangle,
is there a neat way of finding the length of the line section
that is contained within the rectangle?

Would you allow that the rectangles only be those that
are parallel to the x- and y-axes to simplify the problem?

Example:


A rectangle bounded by:

x = a

x = b

y = c

y = d


And the line could be:

y = mx + f **



I do not want to use "e," as it used for a constant.
 
  • #3
checkitagain said:
Example:


A rectangle bounded by:

x = a

x = b

y = c

y = d


And the line could be:

y = mx + f **



I do not want to use "e," as it used for a constant.

Hi there, yes i simplified the problem so that one vertex of the rectangle is at the origin and the extents are positive; the length of any line intersecting any rectangle could then be solved by just adjusting the line intercept and gradient to account for the position and orientation if the rectangle is not at the origin or is rotated.

Actually perhaps it would be easier to assume the rectangle is centered at the origin instead.
 
  • #4
Maybe considering the rectangle to be a line section in the complex plane could help!??!
 
  • #6
Thanks,

Yeah its just normal Cartesian system. Yeah I've looked and only found algorithmic solutions. I think I am probably being stupid, but I was after a mathematical expression that could used in various analyses.
 
  • #7
Hey renucrew and welcome to the forums.

Because the surface/volume/whatever you are talking about is not analytic-continuous/differentiable over the whole surface, you have to do multiple tests instead of one generic test.

As a case of where you could do this, something like a sphere or an ellipse could be used as a single test because it has the required properties, but unfortunately you can't do this with your rectangle.
 

FAQ: The length of a line intersecting a rectangle - not just diagonal

What is the formula for finding the length of a line intersecting a rectangle?

The formula for finding the length of a line intersecting a rectangle is the Pythagorean theorem, which states that the square of the length of the diagonal is equal to the sum of the squares of the other two sides. In this case, the diagonal is the line intersecting the rectangle and the other two sides are the sides of the rectangle that the line touches.

How do you determine the length of a line intersecting a rectangle if the line is not a diagonal?

If the line intersecting the rectangle is not a diagonal, you can use the same formula as the Pythagorean theorem by first finding the length of the diagonal (using the length and width of the rectangle) and then subtracting the lengths of the two sides that the line touches from the diagonal. This will give you the length of the line intersecting the rectangle.

3. Can the length of a line intersecting a rectangle be negative?

No, the length of a line intersecting a rectangle cannot be negative. The length is always a positive value, representing the distance between two points on the line.

4. Are there any other formulas for finding the length of a line intersecting a rectangle?

Yes, there are other formulas for finding the length of a line intersecting a rectangle. One example is the Law of Cosines, which can be used when you have the lengths of two sides of the rectangle and the angle between them.

5. How does the position of the line intersecting a rectangle affect the length?

The position of the line intersecting a rectangle does not affect the length, as long as it still intersects the rectangle. The length is only dependent on the lengths of the sides of the rectangle and the angle of intersection.

Back
Top