Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Random points in triangle
Replies: 8   Last Post: Aug 12, 2010 5:30 AM

 Messages: [ Previous | Next ]
 David Latin Posts: 7 Registered: 6/11/10
Re: Random points in triangle
Posted: Aug 9, 2010 5:15 AM

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@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
>
>

Date Subject Author
8/6/10 Steve Gray
8/7/10 Bill Rowe
8/8/10 Steve Gray
8/8/10 Ray Koopman
8/7/10 Ray Koopman
8/9/10 Bill Rowe
8/9/10 David Latin
8/12/10 Mark McClure
8/12/10 Ray Koopman