Spawning randomly around edge of a circle and not in the center.

阅读更多

 

I am trying to randomly spawn around the edge of a circle and not in the center of the circle?
I am currently spawning with the following:
Random X spawn 100 to -100
Random Y spawn 100 to -100
How do I eliminate the center red area from the equation?

 
Spawning randomly around edge of a circle and not in the center._第1张图片
 

That sounds more like a square than a circle. You might want to just get two random numbers, one from 75 to 100, and another from 0-359. Then use those values to determine the right place relative to the spawner origin.

 

seriously, even if we don't have sin/cos. you can still do this to land points on a circle.

newP = oldP + normalize( vector2d( randomX, randomY)) * radius.

you just have to be sure x/y are not both zero.

with sin/cos you only need one random number and no worry about other situation.

newP = oldP + vector2d( cos(randomDegree), sin(randomDegree)) * radius.

 

Using some basic maths you could do this. Taking the equation for finding a point on the circumference of a circle you just sub the radius to be between your min and max area.

 
Spawning randomly around edge of a circle and not in the center._第2张图片
 

 

  • Spawning randomly around edge of a circle and not in the center._第3张图片
  • 大小: 32.2 KB
  • Spawning randomly around edge of a circle and not in the center._第4张图片
  • 大小: 132.2 KB
  • 查看图片附件

你可能感兴趣的:(random,actor,around,the,circle,or,in,the,annular,area)