CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   Random vector (https://www.cfd-online.com/Forums/main/6564-random-vector.html)

beggin September 15, 2003 04:53

Random vector
 
My problem is: let there is a plane in a 3D space: a*x+b*y+c*z+d=0 and certain point on it (x0,y0,z0). How to find an unit vector (rx,ry,rz) from this point but in random direction in one of hemispheres (so called diffuse scattering on a plane).

Thank you.

Sergei Chernyshenko September 15, 2003 04:59

Re: Random vector
 
Hi,

Generate a random unit vector of arbitrary direction. Throw it away if it points into the wrong semisphere and generate another.

Sergei

beggin September 15, 2003 05:45

Re: Random vector
 
Yes, this is an original and simple variant but 50 % of whole work is in vain. Probably there is more efficient ways?

Sergei Chernyshenko September 15, 2003 07:11

Re: Random vector
 
Then take the mirror image if the vector is pointing in the wrong semisphere. However, random number generation is cheap anyway. Are you sure that CPU time is not consumed by something else?

Sergei.

beggin September 15, 2003 10:31

Re: Random vector
 
Many thanks! May be don't take a mirror image but simply change a sign before "bad" vector?

Sergei Chernyshenko September 15, 2003 10:34

Re: Random vector
 
Yes, it is even better.

Rami September 16, 2003 02:34

Re: Random vector
 
If you wish to do it rigorousy, then you should proceed as follows. Define the the polar angle, theta, as the angle from the normal to the surface in the desired direction. Define the azimuthal angle, phi, as the angle from a predifined vector on the plane (which may be chosen arbitrarily once). It may be shown (by spherical geometry considerations)that the diffuse distribution is obtained by uniform distribution of phi and (sin(theta))^2. The piece of code to find these angles is given below (with Numerical Recipees random number generator).

c ..theta: angle to normal

tht = asin(sqrt(ran1(iseed)))

c ..phi: azimuthal angle

phi = twopi * ran1(iseed)

c ..direction cosines

pno = cos(tht)

pt1 = sin(tht) * cos(phi)

pt2 = sin(tht) * sin(phi)

Now you should transform the resulting unit vector to any convenient coordinate system, e.g.,

c ..direction

ray(1) = pno*norm(1) + pt1*tan1(1) + pt2*tan2(1)

ray(2) = pno*norm(2) + pt1*tan1(2) + pt2*tan2(2)

ray(3) = pno*norm(3) + pt1*tan1(3) + pt2*tan2(3)

beggin September 17, 2003 02:59

Re: Random vector
 
Thank you Rami, you give "scientific foundation" but for practical calculation the approach offered by Sergei is probably more faster.

Rami September 17, 2003 03:36

Re: Random vector
 
I quite agree.


All times are GMT -4. The time now is 00:41.