Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Jan 2, 2012 #1

    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.

  2. jcsd
  3. Jan 2, 2012 #2

    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.
  4. Jan 3, 2012 #3
    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.
  5. Jan 3, 2012 #4
    Maybe considering the rectangle to be a line section in the complex plane could help!??!
  6. Jan 3, 2012 #5


    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

  7. Jan 3, 2012 #6

    Yeah its just normal Cartesian system. Yeah i've looked and only found algorithmic solutions. I think im probably being stupid, but I was after a mathematical expression that could used in various analyses.
  8. Jan 3, 2012 #7


    User Avatar
    Science Advisor

    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook