# Random point generation using a PDF

This topic is 2432 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I was looking at the 'generating points on a hemisphere using a PDF' section at http://people.cs.kul...lCompendium.pdf

I thought I would try them them out in Mathematica.

I noticed that the 'warps' that's on the list consists of ArcCos[r1], while the ones that I compute in Mathematica consists of ArcSin[Sqrt[r1]/Sqrt[...]]. For example, ArcCos[r0] would give me ArcSin[Sqrt[r0]/Sqrt[2]] in Mathematica.

I was initially a bit confused, but after looking at the graphs it make sense. Though they're mirrors of each other across x=0.5, they still generate equal value distributions.

Are there additional trick to do this, or was the ArcCos ones listed because they don't contain square roots?

##### Share on other sites
I'm not exactly sure what distribution you are trying to generate, so I can't comment on that. But avoiding square roots in code that contains acos is a bit weird: inverse trigonometric functions are among the most expensive to compute.

##### Share on other sites
The PDF in question is "Generate random direction on unit hemisphere proportional to cosine-weighted solid angle"
pdf(theta, phi) = cos(theta) / pi (and a implied sin(theta) in there)

The compendium's [0, 1] random to theta function is
theta = acos(sqrt(random))

My computation is as follows (in mathematica):

- get marginal pdf
pdf(theta) = Integrate pdf(theta, phi) sin(theta) from 0->2pi with respect to phi
- get cdf
cdf(a) = Integrate pdf(theta) from 0->a with respect to theta
- invert cdf
solve for a in cdf(a) == random

So cdf(a) is Sin[a]^2
and a = +arcsin(sqrt(random))

My answer is arcsin(sqrt(random)), while the one in the compendium is arccos(sqrt(random))

When graphed, you can tell that they will give equal distributions of values (they're just flipped across x=0.5)

I'm a bit confused on if there's any difference/does it even matter.

Thanks

##### Share on other sites
As far as I can tell the probability density function will be obtained by mapping a uniform distribution to it, so in that respect the two functions are equivalent.

In fact, the PDF's for [eqn]y_1=f(x)[/eqn] and [eqn]y_2 = f(\pi(x))[/eqn] where [eqn]\pi[/eqn] is any permutation on the domain (i.e. a bijection of the domain to itself), are equivalent iff [eqn]x[/eqn] is a random uniform variable over the domain.

So yes, the distributions of [eqn]\arcsin{(\sqrt{x})}[/eqn] and [eqn]\arccos{(\sqrt{x})}[/eqn] with [eqn]0 \leqslant x \leqslant 1[/eqn] random uniform variable are equivalent because one is a permutation of the other under the permutation [eqn]\pi(x) = 1 - x[/eqn] (or more formally, because [eqn]\pi(x) = 1 - x[/eqn] is a bijection of [eqn]0 \leqslant x \leqslant 1[/eqn] to itself)

Note that I am using the term bijection loosely - it should be understood in the sense that the permutation does not skew the random uniform distribution (so in a sense, it would be a bijection of the infinite discrete set of the random uniform distribution)

1. 1
2. 2
Rutin
20
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633762
• Total Posts
3013727
×