Sunday, October 2, 2022
HomeGame Developmentgeometry - Add and Removing Elements on the Circumference of a Circle

geometry – Add and Removing Elements on the Circumference of a Circle

I’m attempting 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 work out 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.measurement() == 0:
  positions.append( {x: radius, y: 0} )
elif positions.measurement() == 1:
  positions.append( {x: -positions[0].x, y: -positions[0].y })
elif positions.measurement() > 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}

Everything breaks down in my for loop when attempting to calculate the third level. This is as a result of the angle after 2 iterations is 0, and ends in a nasty spawn.

My information of geometry will not be actually adequate for me to determine what I must 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 might get this perform capable of robotically discover the proper mid level.

Any assist or route is appreciated.



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments