Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
David Latin

Posts: 7
Registered: 6/11/10
Re: Random points in triangle
Posted: Aug 9, 2010 5:15 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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






Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.