|
|
Severi Salminen wrote:
> I'm trying to create a random uniformly distributed vector through a
> hemisphere positioned at the intersection point between ray and an
> object. I can already create a random vector but how do I quickly/easily
> rotate it based on the desired hemisphere orientation?
>
> I use left-handed coordinatesystem: x is right, y is up, and z is forward.
>
> Let's have a vector V which is random vector inside a hemisphere which
> has a pole at 0,1,0 (just like the northern hemisphere of Earth). I want
> to orient the vector inside a hemishere which has a pole pointing at
> vector N. How do I do this? I'd prefer something that can be done
> without expensive trigonometric functions - if possible.
#local vX=vnormalize(vcross(vN,<vN.y,vN.z,-vN.x>));
#local vY=vnormalize(vcross(vX,vN));
#local sN=rand(YourRandomSeed);
#local sL=sqrt(1-sN*sN);
#local Angle=rand(YourRandomSeed)*360;
#local vResult=sN*vN
+ vrotate(x,y*Angle).x * vX * sL
+ vrotate(x,y*Angle).z * vY * sL ;
vResult is a vector in the hemisphere that faces in the direction of vN.
Regards,
John
Post a reply to this message
|
|