MathGroup Archive 2010

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

Search the Archive

Re: Random points in triangle

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111619] Re: Random points in triangle
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Sat, 7 Aug 2010 06:22:15 -0400 (EDT)
  • References: <i3gpmj$2rm$1@smc.vnet.net>

On Aug 6, 3:55 am, "S. B. Gray" <stev... 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].

The scale parameter in the call to GammaDistribution doesn't matter,
because the scale gets divided out when you take wts/Total[wts], but
the shape parameter should always be 1. Values other than 1 will give
either too many or too few points near the vertices, according as the
shape parameter is less than or greater than 1.


  • Prev by Date: Re: parallel computing and message disabling
  • Next by Date: Re: Default and head in function argument
  • Previous by thread: Random points in triangle
  • Next by thread: Re: Random points in triangle