3
$\begingroup$

I'm trying to figure out a way to generate a random point on the unit circle in an application I am developing (I'm a programmer).

So far I have the following (in pseudo-code), where Z is a random number between 0.0 and 1.0:

theta = (2.0 * PI) * Z  2DVector.x = cos(theta) 2DVector.y = sin(theta)  result: 2DVector 

I know that it's wrong, as I'm getting nothing but massive x values and tiny y values. But I'm not familiar enough with the unit circle mathematics to know where I'm going wrong!

  • 0
    And in fact it does! It was a silly casting-error on my part in the code. So the above it a perfectly way of getting a random point on the unit circle! ;)2011-05-19

1 Answers 1

2

The example I provided works fine, so long as it's implemented properly.

  • 0
    I am not 100% sure I am correct but, just in case, I think that the random number has to be in the range `[0,1)`. Sine of Tau is.... something strange? (In C# I get `-2.449213E-16`)2018-10-17