Path: news.mathworks.com!not-for-mail
From: "Peter Bone" <peterbone@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Random points in a circular zone
Date: Wed, 23 May 2012 15:18:07 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 26
Message-ID: <jpiv3f$pid$1@newscl01ah.mathworks.com>
References: <jpi7su$g55$1@newscl01ah.mathworks.com>
Reply-To: "Peter Bone" <peterbone@hotmail.com>
NNTP-Posting-Host: www-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1337786287 26189 172.30.248.47 (23 May 2012 15:18:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 23 May 2012 15:18:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 870367
Xref: news.mathworks.com comp.soft-sys.matlab:768758

"Valentina" wrote in message <jpi7su$g55$1@newscl01ah.mathworks.com>...
> Hi, I want to create a function that give me N random points in a circular zone.
> 
> The circular zone can be represented as
> A={(x,y)=(R*cos(theta), R*t*sin(theta)), t in [-1, 1], theta in [a,b]}
> where 0<a<b<pi.
> 
> I have written a function for the circular segment, that is when a=0, but this function doesn't give me a uniform distribution and I don't understand how apply it to the zone.
> 
> function [x,y]= RandSeg(N, R, w)
>     angle = -w+2*w*rand(N,1);    % theta is in [0, w]
>     k=linspace(-1,1,N)';
>     x=R.*cos(angle);
>     y=R.*k.*sin(angle);
> 
> Can anyone help me?
> Thank you!
> Valentina

Actually, here's a better vectorised method. The square root provides the uniform distribution.

function [x,y]= RandSeg(N, R, w)
  angle = -w+2*w*rand(N,1);
  rad = rand(N,1).^0.5;
  x=R*rad.*cos(angle);
  y=R*rad.*sin(angle);