0
$\begingroup$

Hi,

I need to generate a 'uniform sample' over an hemisphere and once done project it in a specific vector direction.

I have try the following, but it produce some errors... maybe you have an idea ? I have another solution, but I don't understand why this one does not work !

1. Create a random direction

x = random() * 2 - 1

y = random() * 2 - 1

z = random() * 2 - 1

d = normalize(x,y,z) // Scale it to have vector lenght = 1

2. Project the sample into the direction

dp = dot_product(d, direction)

if dp <= 0 then result = -d

else result = d

Thanks

$\endgroup$
1

1 Answer 1

1
$\begingroup$

This is fully discussed in

Efficiently sampling points uniformly from the surface of an n-sphere

$\endgroup$
5
  • $\begingroup$ Thanks, I have read it both references. I already use one of the solution in the Wolfram reference (this one works of course). But, the solution that does not work for me is the last of from the Wolfram link, formula (16). So, it should work ! $\endgroup$
    – spectral
    Jul 17, 2012 at 9:39
  • $\begingroup$ I use simple random numbers that I scale between [-1,1] like this : (rnd*2-1) $\endgroup$
    – spectral
    Jul 17, 2012 at 9:40
  • 2
    $\begingroup$ In the last variant in the Wolfram link you're supposed to use normally distributed random variables, yours are not. In any case, your questions are off topic on this site, which is about research level mathematics question. In the future you would be better off asking at math.stackexchange.com $\endgroup$ Jul 17, 2012 at 9:55
  • $\begingroup$ Thanks, Why my random values are not "normally distributed" ? $\endgroup$
    – spectral
    Jul 17, 2012 at 10:02
  • 1
    $\begingroup$ For a reason that won't be given here, since the question is off topic. $\:$ (See Dan's comment.) $\endgroup$
    – user5810
    Jul 17, 2012 at 10:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.