Random Coordinates Outside a Circle

Hi all,

I understand that there's a Random.insideUnitCircle variable to get a random 2D coordinate inside a theoretical circle.

But what if I wanted to get a random 2D coordinate outside of that theoretical circle? Any ideas on how to go about that?

Thanks in advance,

Dendro

1 Answer

1

Broadly, this is what I would do:

  1. Randomise a position within the min/max bounds
  2. Check distance from the centrepoint to the randomised position
  3. If it's less than a desired radius, recalculate the random position

Be aware that sqrMagnitude is much faster than Vector2.magnitude. To use this, you will then obviously need to square the radius value. For example:

if ( (randomPos.position - centrePoint.position).sqrMagnitude <= radius*radius )
{ // retry }

Thanks Marowi. I'm not entirely sure on how to 'reply to an answer', and I hope I'm doing it right. I'll try out what you've suggested. Just a thought, though, isn't the logic you are suggesting quite similar to a brute-force solution? Thanks again.

Hi Marowi, really sorry for the superbly late feedback on this. Although I wasn't able to impplement your code solution, I did use the concept you had suggested and came up with a rather cruder (if there is such a word hehe..) way of generating points outside a circle. To that extent, I do believe that the concept you suggested still answered my question. Thanks again! btw: how do you post an answer to your own question?