MathGroup Archive 2010

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

Search the Archive

Random points in triangle

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: Rearrange equation
  • Next by Date: Re: A new graphic user interface
  • Previous by thread: Re: Convex hull in 3D
  • Next by thread: Re: Random points in triangle