From: "Peter Bone" <>
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$>
References: <jpi7su$g55$>
Reply-To: "Peter Bone" <>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1337786287 26189 (23 May 2012 15:18:07 GMT)
NNTP-Posting-Date: Wed, 23 May 2012 15:18:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 870367
Xref: comp.soft-sys.matlab:768758

"Valentina" wrote in message <jpi7su$g55$>...
> 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;