
[Sponsors] 
September 15, 2003, 04:53 
Random vector

#1 
Guest
Posts: n/a

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. 

September 15, 2003, 04:59 
Re: Random vector

#2 
Guest
Posts: n/a

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

September 15, 2003, 05:45 
Re: Random vector

#3 
Guest
Posts: n/a

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


September 15, 2003, 07:11 
Re: Random vector

#4 
Guest
Posts: n/a

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. 

September 15, 2003, 10:31 
Re: Random vector

#5 
Guest
Posts: n/a

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


September 15, 2003, 10:34 
Re: Random vector

#6 
Guest
Posts: n/a

Yes, it is even better.


September 16, 2003, 02:34 
Re: Random vector

#7 
Guest
Posts: n/a

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) 

September 17, 2003, 02:59 
Re: Random vector

#8 
Guest
Posts: n/a

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


September 17, 2003, 03:36 
Re: Random vector

#9 
Guest
Posts: n/a

I quite agree.


Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
how to set periodic boundary conditions  Ganesh  FLUENT  13  January 22, 2014 05:11 
Assign one vector to another  still a field?  David*  OpenFOAM  3  May 27, 2011 10:47 
UDF for wall slipping  HFLUENT  Fluent UDF and Scheme Programming  0  April 27, 2011 12:03 
Normal vector, slope and aspect angle  g_niro  Main CFD Forum  0  February 2, 2011 18:24 
what is gradient vector?  majestywzh  FLUENT  0  April 13, 2003 23:57 