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$>
References: <hv7gk8$289$> <hv7ol1$k3n$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1276604226 18263 (15 Jun 2010 12:17:06 GMT)
NNTP-Posting-Date: Tue, 15 Jun 2010 12:17:06 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:645034

"Roger Stafford" <> wrote in message <hv7ol1$k3n$>...
>   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