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

Orientation of lines?

  1. Jul 14, 2010 #1
    Hi everyone,

    I have a question that seems simple, but I cannot come up with the right answer.

    Suppose you have a square with sides 2 (xrange[-1:1], yrange[-1:1])

    Further suppose that there are equal number of vertical, horizontal and diagonal (exactly 45 degrees) lines of various lengths inside the square.

    Now draw a square inside with sides 1 (xrange[-0.5:0.5],yrange[-0.5:0.5]).
    The goal is to find the overall statistics of line orientation in the bigger square from looking at the line statistics inside smaller square.

    I wrote a simple program to count the number of lines inside the square for each type of orientation, and found that there are always slightly more diagonal lines(vertical and horizontal are about the same).

    When I change the sample space, lets say to something like a rectangle of width 2 and height 1 (xrange[-1:1] yrange[-0.5:0.5]) I get more vertical counts than horizontal counts with diagonal count in between.

    From these results I calculate the average orientation of lines for different sample spaces and get different answers (so it doesn't give me the right average orientation of the lines in the larger square).

    What I am currently thinking is adding a component of "weight" in certain directions when calculating the average, so that no matter what shape the sample space is, the weighted average will approximately be the same.

    Now my question is, how would you determine this "weight"?
    I've tried simple things like the distance from the center to the edge of the sample space but it didn't work.

    Anyone have any ideas or experience with this kind of thing?

    Thank you so much!
  2. jcsd
  3. Jul 14, 2010 #2
    I think the most precise way is to find an equation for the line count distribution.
    Each line has three parameters (horizontal lines: x1,x2,y; vertical lines x,y1,y2; diagonal lines: x1,y,x2)
    Now you can assume some distribution for these independent coordinates. Maybe a uniform makes most sense. Then you can predict the average number of lines found in a square (for example a horizontal line is in the square if a<x1<b or a<x2<b or x1<a<b<x2 AND c<y<d....; use probability theory with things as integrals)
    From this you can find the equation to convert from average counts in one square to average counts in another square.

    Horizontal and vertical lines are very easy.
    But note that for diagonal lines you have some funny line crossing a corner only.
  4. Jul 15, 2010 #3
    Thanks for your reply Gerenuk,

    Yes, when the sides are flat I think theres an easy way to calculate the probability.
    Now, I really don't know about the intermediate angles (1 to 89 degrees).
    Something to do with spatial sampling bias I suppose...hmm..
  5. Jul 20, 2010 #4


    User Avatar

    There may be some way of calculating the weight you should use, but it will change based on the distribution of the length of the lines. I think a key question is: if you find a line in your smaller square with one or more endpoints that lie outside the smaller square (so you only see a segment of the overall line), do you have access to the full length of that line? If so, I think you can come up with a pretty good guess for the number of lines and lengths in the larger square from the smaller square. If not, maybe not.

    For the very, very small lines, you can assume that the lines you see inside the smaller square are representative of the lines contained in the larger square (assuming your lines are uniformly randomly distributed in the larger square).

    As your lines get larger, you will see a greater percentages of the diagonal lines than the horizontal or vertical. When your line lengths are sqrt(2) or larger, it becomes impossible to place a diagonal line within the larger square that is not also visible in the smaller square, so you know you can see 100% of all the diagonal lines longer than sqrt(2). In contrast you can see only 50% of all the horizontal and vertical lines of that length that exist in the larger square by looking in the smaller square. (50% of horizontal and vertical lines with length .5 or greater are visible in the smaller square).

    I think for horizontal lines and vertical lines, you're right, it's pretty easy... I think.
    You miss 50% of all the horizontal lines straight off, if Y>.5 or <-.5.

    Of all the horizontal lines for which -.5<y<.5,
    When the horizontal lines are > length of .5 you can see all of them in the smaller square.​
    When the horizontal lines are 0< length L < .5 you can see... 1-(1-2L)/(2-L) of them​

    Or, looking at all horizontal lines, -1 < y < 1, you see:
    25% of all lines of ~0 length
    50% of all lines of .5 or greater length
    and .5*(L+1)/(2-L) of all the other lines where L = length of line.

    ...Should be able to work backwards from there.

    Diagonals and other angles should be possible in the same way, but with slightly more complicated math...
  6. Jul 23, 2010 #5
    Thanks for your reply kjl.

    I've now tried a whole bunch of things, and have come to a final result.
    After taking different approaches to this problem, including the weight method and the probability method, I noticed that the real problem comes into play when the sample space is extremely narrow. In such sample spaces, the number of lines going through the widest part is greatest (i.e if the sample space is a narrow vertical strip then there will be more horizontal lines going through the sample space than vertical ones)

    I am actually pretty sure using probability is the way to take an estimate of the overall distribution of line orientation. But even if it possible to find such average value, i'm not too sure if the uncertainty is acceptable (it's probably going to be huge).

    So the approach I took was:
    1.generate random lines in a space with the same dimensions as the sample space
    2.measure the orientation of each lines
    3. discretized the angle, and count how many lines have the same orientation
    4.compute (#lines with orientation X in data)/(#lines with orientation X in random data)
    5.use the computed value as the "weight" to calculate the average.

    The results are looking good (so far) , and I am hoping I find no problem with this approach.

    Thanks to Gerenuk and kjl for providing me ideas, and everyone else who took a look at this thread!
  7. Jul 23, 2010 #6


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    I think for the diagonal lines, it might be easier conceptually (to avoid errors) to tilt the squares 45 degrees. Then apply an argument like kjil's to your newly made vertical lines, noting that the probability of landing inside the smaller square depends on where the line is located horizontally. You'll have to integrate a probability distribution but I imagine it will be a simple function
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook