This is a lot more complicated than it might seem at first. What I have is a giant array which consists of more arrays which contain points [in the form of an array "x,y"] like so:
Array (
[0] => Array (
[0] => "0,9",
[1] => "0,0",
[2] => "9,0",
[3] => "9,9",
[4] => "0,9"
)
[1] => Array (
[0] => "1,5",
[1] => "1,6",
[2] => "3,6",
[3] => "3,8",
[4] => "4,8"
)
... and so on ...
)
So what I need to do is process through all the points and see if any point in an array, say $points[0][1]
to $points[0][2]
, intersects with any other line segment that could exist in the array. All the line segments are consecutive following the order they are in within each of their respective arrays. So in the first array, "0,9" goes to "0,0" and no other point in that array. The last point in an array does not loop back around to the first point in an array. Also, it should not be considered an intersection if a line segment ends at the intersection of another line segment, it actually needs to cross the line segment it intersects.
I was thinking of plotting the segments as I processed them. So like run through the arrays plotting each point on a 'virtual' grid per say and then each array after that would calculate if it intersects another segment which is already plotted, if that makes any sense, but that still seems like it might take a while to calculate if there are a lot of line segments in the array. It seems like what I'd be doing is for each segment in an array, calculate if it intersects any segments previous to it (because theoretically it could intersect a segment in the same array it is in). There has got to be a simpler way to do this, right?
P.S. I couldn't really think of what tags this should fall under other than PHP. If you think of any please feel free to retag it.