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

renucrew
Messages
6
Reaction score
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
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.
 
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.
 
Maybe considering the rectangle to be a line section in the complex plane could help!??!
 
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.
 
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.
 
Back
Top