Can anyone please help.
I have a problem where I need to loop through 3 lines and check if they are intersecting using C#. The 3 lines will make up the general shape of a triangle. Therefore, only 2 lines will ever be intersecting at a a time.
I have 3 Line objects and I have stored them in List lines. My method to check for intersections currently looks like this:
ProcessIntersections(lines[0], lines[1])
ProcessIntersections(lines[1], lines[2])
ProcessIntersections(lines[2], lines[0])
Looping through the list once I can do, but to check the final intersection, I have to pass in the first line again and check it against the last line.
Is there a better way to process my intersections? How would I be able to loop through the list of lines by only calling ProcessIntersections once? I tried:
for (int i = 0; i < lines.Count; i++)
{
if (i >= 3)
{
i = 0;
ProcessIntersection(lines[i], lines[i + 1]);
}
}
But this just lands me in an infinite loop as i keeps on resetting to 0.
Does anyone have any suggestions.
ProcessInteractionsmultiple times? If this method compares two lines for intersection then it does exactly what you want with your first code example. The whole point of creating methods is to be able to re-use the code and call it multiple times with different input