I have a list points
of triples containing (x, y, z) where x is the x-coordinate, y is the y-coordinate and z is a magnitude. Now I want to check if any point in the list is within a certain radius to the other points in the list. If so the point in the radius has to be deleted. Therefore I made the following code.
radius = 20
for _, current_point in enumerate(points):
# get the x and y coordinate of the current point
current_x, current_y = current_point[0], current_point[1]
for _, elem in enumerate(points):
# check if the second point is within the radius of the first point
if (elem[0] - current_x)**2 + (elem[1] - current_y)**2 < radius**2:
# remove the point if its within the radius
points.remove(elem)
When I run this the list still contains points which are within the radius of another point. Is there some property of enumerate
that I'm missing here?
question from:
https://stackoverflow.com/questions/65880856/using-enumerate-in-nested-loops-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…