MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Random points in triangle

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111665] Re: Random points in triangle
  • From: David Latin <d.latin at gmail.com>
  • Date: Mon, 9 Aug 2010 05:15:18 -0400 (EDT)

For a much simpler and probably naive approach, what about filtering for
those random coordinates lying inside a triangle bounded by:
y>x, y<x, y<1-x
I know this is not very sophisticated, but randomly generated points inside
a rectangle should be random inside a triangle also.

pts = RandomReal[{0, 1}, {10^5, 2}] ;
ptsT = Select[ pts, ( #[[2]] >= 0 && #[[2]] < #[[1]] && #[[2]] < 1 - #[[1]]
) & ] ;
ListPlot[ ptsT, PlotStyle -> PointSize[.001] ]

David


On 6 August 2010 17:55, S. B. Gray <stevebg at roadrunner.com> wrote:

> I was looking for a simple way to place random points inside a triangle
> with uniform distribution. Here's a good way:
>
> newtri := Module[{x},
>   ptri = RandomReal[{-5, +5}, {3, 2}];
>   tredg = Subsets[ptri, {2}];
>   ]
> newpts[nump_] := Module[{wts},
>   inpoints = {};
>        Do [ wts = RandomReal[GammaDistribution[1, 2], 3];
>           wts = wts/Total[wts];
>           newin = Total[ptri*wts];
>          inpoints = Append[inpoints, newin], {nump}];
>   ]
> shotri := Module[{x},
>   Graphics[{Blue, Line[tredg], Red, Point[inpoints]}, ImageSize -> 500]
>   ]
>
> The same idea works for points in a tetrahedron; they will be uniformly
> distributed if you use args such as GammaDistribution[.6,.1].
>
> Steve Gray
>
>



  • Prev by Date: Re: ExistsURLQ
  • Next by Date: remote kernel problem
  • Previous by thread: Re: Random points in triangle
  • Next by thread: Re: Random points in triangle