Reputation: 95
I have a dictionary with street names as keys and co-ordinates as values as below.
{'"a street"': '(2,2) (3,1) (4,-1)', '"b street"': '(1,1) (5,1)', '"c street"': '(5,1) (6,6)'}
I want to check if there is intersection between each street with all the other streets using the street co-ordinates. Is there any simple way to go for it?
Thanks.
Upvotes: 0
Views: 94
Reputation: 2217
Here is some pseudocode that might spark some ideas as to how to implement the multi-line interesection problem, consider trying to implement these functions:
def coords_string_to_list_of_tuples(str):
...
def line_from_two_tuples(tuple1,tuple2):
...
def line_intersects_line():
...
def check_intersection(line1, line2):
...
def print_intersections():
for each street s:
coord_tuple_list = coords_string_to_list_of_tuples(list[s])
for each street s2:
if s1 ≠ s2:
print check_intersection(list[s], list[s2])
I hope these ideas provide guidance.
Upvotes: 1