So I'm kind of stuck trying to program a function that returns a list of tuples. The function takes 2 lists containing circles of which it should compare list1[0] to list2[0] to see if they intersect. If they intersect or touch then I should return them on a list of tuples(in the tuple would be both intersecting circles).
I can't get circles_only to work the way I see it I'm comparing h to x only if they're both in the same place on the list (hence my "h==x") I know it doesn't work because the test returns None so I would really appreciate an alternative method if you guys see one. Here are my functions: def circles_overlap(c1, c2): x=(c2.center.y-c1.center.y)**2 y=(c2.center.x-c1.center.x)**2 distancemid=math.sqrt(x+y) distancerad=(c1.radius+c2.radius) if distancemid > distancerad: return 1 elif distancemid < distancerad: return -1 elif distancemid == distancerad: return 0 def circles_only(lst1, lst2): newlst=[] for h in lst1: for x in lst2: if h==x: if circles_overlap(lst1[h],lst2[x])== -1: newlst.append(lst1[h],lst2[x]) elif circles_overlap(lst1[h],lst2[x])== 0: newlst.append(lst1[h],lst2[x]) print newlst TEST CASE: def test_circles_olap1(self): list1=[data_2.Circle(data_2.Point(2,3), 2),data_2.Circle(data_2.Point(2,3), 2), data_2.Circle(data_2.Point(2,3), 2) ] list2=[data_2.Circle(data_2.Point(6,3), 2),data_2.Circle(data_2.Point(10,3), 2), data_2.Circle(data_2.Point(5,3), 2) ] testor=functions_2.circles_only(list1,list2) newlist=[(data_2.Circle(data_2.Point(2,3), 2),data_2.Circle(data_2.Point(6,3), 2)),(data_2.Circle(data_2.Point(2,3), 2),data_2.Circle(data_2.Point(10,3), 2))] self.assertEqual(testor, newlist) Thanks in advance! _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor