Random points in triangle
- To: mathgroup at smc.vnet.net
- Subject: [mg111573] Random points in triangle
- From: "S. B. Gray" <stevebg at ROADRUNNER.COM>
- Date: Fri, 6 Aug 2010 06:55:22 -0400 (EDT)
- Reply-to: stevebg at ROADRUNNER.COM
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