```Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: generate random points in any shaped polygon?
Date: Tue, 15 Jun 2010 12:17:06 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 13
Message-ID: <hv7r02\$hqn\$1@fred.mathworks.com>
References: <hv7gk8\$289\$1@fred.mathworks.com> <hv7ol1\$k3n\$1@fred.mathworks.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1276604226 18263 172.30.248.35 (15 Jun 2010 12:17:06 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 15 Jun 2010 12:17:06 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:645034

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hv7ol1\$k3n\$1@fred.mathworks.com>...
>   See the discussion on this subject in the June 5, 2008 thread at:
> Roger Stafford

Added note: If your polygon is divided up into a large number of triangles, you can use the 'histc' function to choose points among them in proportion to their area.  Let a = [A1 A2 A3 ... An] be a vector of their areas.  Let N be the total number of random points you want to choose.

c = cumsum([0 a]); c = c/c(end); c(end) = inf;
b = histc(rand(N,1),c); b(end) = [];

Then b will be a vector with n elements with a total count of N containing the numbers of points selected for each of the respective triangles, and these will have been selected randomly in proportion to their areas.

Roger Stafford
```