I’m making an attempt to spawn entities on the circumference of a circle.
These entities could also be eliminated at any time, together with all of them being eliminated.
Periodically I wish to add a component on the circle on the furthest distance from all different entities, however I can’t determine the maths.
The fundamentals is so as to add an entity on the midpoint between the 2 neighbors which have the best distance between them.
My pseudo code is –
positions = []
radius = 40
max_angle = 0
if positions.dimension() == 0:
positions.append( {x: radius, y: 0} )
elif positions.dimension() == 1:
positions.append( {x: -positions[0].x, y: -positions[0].y })
elif positions.dimension() > 1:
for i in [0 to positions.size()]:
p1 = positions[i]
p2 = positions[i + 1 % positions.size()]
angle = atan2(p2.y - p1.y, p2.x - p1.x)
if angle > max_angle:
temp = {x: cos(angle/2) * radius, y: sin(angle/2) * radius}
positions.append(temp)
Every part breaks down in my for loop when making an attempt to calculate the third level. It’s because the angle after 2 iterations is 0, and leads to a foul spawn.
My data of geometry is just not actually ok for me to determine what I needs to be doing right here.
I’ve some work arounds which might contain including static factors on the circle, or redistributing factors alongside the circle on a brand new spawn, however it will be fairly cool if I may get this operate in a position to routinely discover the right mid level.
Any assist or path is appreciated.