Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Generate random points on a circular sector
Date: Sun, 6 May 2012 16:36:08 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 19
Message-ID: <jo699n$mb6$1@newscl01ah.mathworks.com>
References: <jo6784$eqn$1@newscl01ah.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
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 1336322168 22886 172.30.248.47 (6 May 2012 16:36:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 6 May 2012 16:36:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:767003

"Valentina" wrote in message <jo6784$eqn$1@newscl01ah.mathworks.com>...
> Hi.
> 
> I am trying to generate random points in cartesian coordinates inside a circular sector defined by the radius R and the angle w (I suppose the center in (0,0) and that the angle is in [-w,w]).
> 
> If anyone has a sample code or can help me with this, thanks for the help.

% Generate n points uniformly in the polar region (r,theta) in (0,1) x (0,w)
n=1e4;
w = pi/3;
r=sqrt(rand(1,n));
theta=rand(1,n)*w;
x=r.*cos(theta);
y=r.*sin(theta);

plot(x,y,'.')
axis equal

% Bruno