CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Main CFD Forum

Random vector

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

Reply
 
LinkBack Thread Tools Display Modes
Old   September 15, 2003, 04:53
Default 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.
  Reply With Quote

Old   September 15, 2003, 04:59
Default 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
  Reply With Quote

Old   September 15, 2003, 05:45
Default 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?
  Reply With Quote

Old   September 15, 2003, 07:11
Default 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.
  Reply With Quote

Old   September 15, 2003, 10:31
Default 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?
  Reply With Quote

Old   September 15, 2003, 10:34
Default Re: Random vector
  #6
Sergei Chernyshenko
Guest
 
Posts: n/a
Yes, it is even better.
  Reply With Quote

Old   September 16, 2003, 02:34
Default 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)
  Reply With Quote

Old   September 17, 2003, 02:59
Default 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.
  Reply With Quote

Old   September 17, 2003, 03:36
Default Re: Random vector
  #9
Rami
Guest
 
Posts: n/a
I quite agree.
  Reply With Quote

Reply

Thread Tools
Display Modes

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 10:54.