From: David Latin on
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(a)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
>
>


From: Bill Rowe on
On 8/8/10 at 7:21 AM, stevebg(a)ROADRUNNER.COM (S. B. Gray) wrote:

>Bill, Thank you for your careful reply. I will consider what you
>say. In the meantime, if you run the code I sent, you will see that
>the triangle is filled with a pretty good uniform distribution.
>Visual uniformity is really all that I need, not any statistical
>tests.

If you are getting a result that satisfies your needs, great.
Certainly, there are solutions that will not meet statistical
tests for uniformity that appear to be visually uniform. And if
all you need is the appearance of being uniform, there is
clearly no need to worry about meeting any statistical test. But
if you are using this as a basis for computing something else
and need confidence limits on the answer you can find yourself
significantly mislead if you rely on just the visual appearance.

>Another factor is that I have convex 3D polyhedra to be
>filled "uniformly." It turns out that the Gamma distribution does a
>decent job with a good setting of the first parameter; the more
>points there are in the convex polyhedron, the lower that parameter
>should be for good uniformity. (There is one weight, 0<wts<1, per
>vertex and the resulting point is always inside the polyhedron.)

One of the advantages of using the approach I suggested is there
is no need to "tune" the parameters of the algorithm for
different shapes. All that is needed is a suitable definition
for inside/outside of the particular shape you want to use.

>The purpose for the random internal points (and random convex
>polyhedra) is to test a conjecture that I thought of. The conjecture
>has to do with the angles between the n rays from a random point inside
>the convex polyhedron to its n vertices. There are n(n-1)/2 angles
>between pairs of rays and the conjecture is that at least n-1 of them
>must be obtuse. This may be easy or difficult to prove - I don't know,
>and if you have any ideas I'd be glad to hear them.

=46or this purpose, you probably don't even need something that is
visually uniform. All you really need is to ensure the points
are interior points and the algorithm you use has some
probability of choosing any interior point. If your algorithm
chooses say edge points less often than strictly interior
points, all you would need to do is increase the number of
random points selected to ensure some edge points are selected.

But there is a potential problem if you either choose an
algorithm that is not visually uniform or only insist on the
appearance of uniformity. It is more difficult to be certain
such an algorithm will not overlook special cases. The more
complex the algorithm is, the more difficult it is to analyze to
determine whether all important cases are considered.

In your algorithm, you start with values selected from an
exponential distribution which is unbounded. Then you do a
series of computations to get a weight which will have a beta
distribution which is bounded. While it should be possible to
work out the bounds for the weight value you use, it clearly is
not immediately obvious what the bounds for this variable are.
And that makes it hard to immediately see if your algorithm is
doing what you intend.


From: Mark McClure on
On Sun, Aug 8, 2010 at 7:23 AM, Ray Koopman <koopman(a)sfu.ca> wrote:
> Try this a few times. It looks pretty uniform to me.
>
> p == RandomReal[NormalDistribution[0,1],{3,2}];
> r == #.p / Total[#,{2}] & @
> RandomReal[ExponentialDistribution[1],{5000,3}];
> ListPlot[{p,r},PlotRange->All,AspectRatio->1,Frame->True,Axes->None,
> PlotStyle->{{Red,PointSize[.02]},{Black,PointSize[.005]}}]

Yes, it turns out that it *must* be. According to Wikipedia, the
obvious generalization works for the n-simplex:
http://en.wikipedia.org/wiki/Simplex#Random_sampling

If you are happy working with change of variables for triple integrals
and joint probability distributions, then the triangular case isn't
too hard. Here's my proof:
http://facstaff.unca.edu/mcmcclur/blog/UniformTriangle.html

Mark McClure

From: Ray Koopman on
On Wed, 11 Aug 2010 at 2:00 PM, Mark McClure <mcmcclur(a)unca.edu> wrote:
> On Sun, Aug 8, 2010 at 7:23 AM, Ray Koopman <koopman(a)sfu.ca> wrote:
>> Try this a few times. It looks pretty uniform to me.
>>
>> p = RandomReal[NormalDistribution[0,1],{3,2}];
>> r = #.p / Total[#,{2}] & @
>> RandomReal[ExponentialDistribution[1],{5000,3}];
>> ListPlot[{p,r},PlotRange->All,AspectRatio->1,Frame->True,Axes->None,
>> PlotStyle->{{Red,PointSize[.02]},{Black,PointSize[.005]}}]
>
> Yes, it turns out that it *must* be. According to Wikipedia, the
> obvious generalization works for the n-simplex:
> http://en.wikipedia.org/wiki/Simplex#Random_sampling
>
> If you are happy working with change of variables for triple integrals
> and joint probability distributions, then the triangular case isn't
> too hard. Here's my proof:
> http://facstaff.unca.edu/mcmcclur/blog/UniformTriangle.html
>
> Mark McClure

I've been thinking about this, too, and had to ask for help.
For the general case, see the thread "Uniform points in a simplex",
http://groups.google.ca/group/sci.stat.math/browse_frm/thread/3c3d783438fa844a#