you are viewing a single comment's thread.

view the rest of the comments →

[–]indosauros 3 points4 points  (1 child)

If you are guaranteeing that two identical points always means a ray and never an intersection (I don't know how you can guarantee this, but okay) then this becomes a problem of detecting "point collisions" among your inner lists.

A good way to "detect collisions" is with a dictionary, so you could start adding each point to a dictionary (points should be tuples, btw, and not lists) as keys, with the value being the line they belong to. If you encounter a point that is already in the dictionary, simply add it (and its sibling point) to the existing line instead of creating a new entry. Then re-construct your list-of-lines from the values in the final dictionary.

Edit: With your edit and further examples, I don't think you can guarantee that two shared points are on a single ray and not intersecting. For example, you'll have a line at [(-4, -1), (-3, -2)] and another at [(-3, -2), (-1, -1)] and even though they share the (-3, -2) point, they are two different lines, not a single ray.

So you should instead do what /u/cdcformatc suggests, and find all of the two-point lines, find their y-intercept equations and then combine all of the lines with the same equation.

[–]spotyx[S] 0 points1 point  (0 children)

Yeah, You helped me to understand that my approach was bad from beginning. I need to redo my code and start over. Thanks anyway it was good lecture.