I would like to remove the elements that are close to each other or if it is just a duplicate
For example, I have a list containing (x,y) the center of the circle and radius its shows like:
[(149, 483, 55), (149, 484, 56), (279, 526, 56), (148, 483, 57), (149, 485, 57), (279, 526, 57), (279, 527, 57), (148, 486, 58), (495, 482, 65), (493, 482, 66)...]
cannot be a circle on the circle so if I have x = 149, y= 483, radius = 55 like the first element in the list, so cannot be the second element with radius 56 at the same position
or another example (148, 483, 57), (149, 485, 57) this is the same radius, same x, and only difference of 2 in the y.
I want to keep the x, y, radius only once per circle while each circle has a different (x,y) I mean What separates each circle is the distance from the center of any circle that can not exceed the minimum radius squared
From this list:
[(149, 483, 55), (149, 484, 56), (279, 526, 56), (148, 483, 57), (149, 485, 57), (279, 526, 57), (279, 527, 57), (148, 486, 58), (495, 482, 65), (493, 482, 66)...]
OutPut :
[(149, 483, 55), (279, 526, 56), (495, 482, 65)...]
because each value of the input list has an epsilon environment of 50 in x and y
CodePudding user response:
If I understand correctly, this should work:
# First get rid of exact duplicates, not necessary but reduces some of the work
circles = set(circle for circle in list_of_circles)
# or cast to set, if the order of the circles doesn't matter
# Helper function returns True if all components between two circles are within eps
def overlaps(C1, C2, eps):
return all(abs(c2 - c1) < eps for c2, c1 in zip(C2, C1))
# Add only circles that do not "overlap"
eps = 50
new_circles = set()
while circles:
circle = circles.pop()
for other in circles:
if overlaps(circle, other, eps):
break
else:
new_circles.add(circle)
Output:
{(149, 484, 56), (279, 526, 56), (493, 482, 66)}
To be honest, I find your criteria for what constitutes an "overlap" a little confusing. Why not just check that the distance between two circles is greater than the sum of their radii?