---
title: "Spawning randomly around edge of a circle and not in the center. "
author: "AVI"
date: "2019-01-18T14:29:39Z"
tags: []
categories: ["行业应用"]
slug: "spawning-randomly-around-edge-of-a-circle-and-not-in-the-center"
draft: false
lastmod: "2019-01-18T14:29:59Z"
id: 2436779
url: "https://avi.iteye.com/blog/2436779"
---

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?

   
![](http://dl2.iteye.com/upload/attachment/0131/4493/79b1baad-512f-34ee-9cca-648dd66793b7.png)  
 

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.

   
![](http://dl2.iteye.com/upload/attachment/0131/4497/8fd89261-9bfd-3683-b1ca-e26e0a5c0b20.png)