# Random vector

 Register Blogs Members List Search Today's Posts Mark Forums Read

 September 15, 2003, 04:53 Random vector #1 beggin 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 Sergei Chernyshenko 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 beggin 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 Sergei Chernyshenko 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 beggin 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 Sergei Chernyshenko Guest   Posts: n/a Yes, it is even better.

 September 16, 2003, 02:34 Re: Random vector #7 Rami 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 beggin 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 Rami Guest   Posts: n/a I quite agree.

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Ganesh FLUENT 13 January 22, 2014 05:11 David* OpenFOAM 3 May 27, 2011 10:47 HFLUENT Fluent UDF and Scheme Programming 0 April 27, 2011 12:03 g_niro Main CFD Forum 0 February 2, 2011 18:24 majestywzh FLUENT 0 April 13, 2003 23:57

All times are GMT -4. The time now is 19:49.