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. |
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 |
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?
|
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. |
Re: Random vector
Many thanks! May be don't take a mirror image but simply change a sign before "bad" vector?
|
Re: Random vector
Yes, it is even better.
|
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) |
Re: Random vector
Thank you Rami, you give "scientific foundation" but for practical calculation the approach offered by Sergei is probably more faster.
|
Re: Random vector
I quite agree.
|
All times are GMT -4. The time now is 04:33. |