POV-Ray : Newsgroups : povray.general : Vector calculation/rotation problem Server Time
31 Jul 2024 02:24:14 EDT (-0400)
  Vector calculation/rotation problem (Message 1 to 7 of 7)  
From: Severi Salminen
Subject: Vector calculation/rotation problem
Date: 16 Feb 2008 09:04:58
Message: <47b6ed8a@news.povray.org>
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.

PS. If this is the wrong forum, please advice.


Post a reply to this message

From: Severi Salminen
Subject: Re: Vector calculation/rotation problem
Date: 16 Feb 2008 09:09:03
Message: <47b6ee7f$1@news.povray.org>
Severi Salminen wrote:

> 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? 

Example:

V = (0.71, 0.71, 0) //The random vector in "northern hemishpere")
N = (-1,0,0) //The pole I want to orientate the random vectors to)

The result is

Vnew = (-0.71, 0.71, 0)


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Vector calculation/rotation problem
Date: 16 Feb 2008 14:38:32
Message: <47b73bb8$1@news.povray.org>
Severi Salminen wrote:
> Severi Salminen wrote:
> 
>> 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? 
> 
> Example:
> 
> V = (0.71, 0.71, 0) //The random vector in "northern hemishpere")
> N = (-1,0,0) //The pole I want to orientate the random vectors to)
> 
> The result is
> 
> Vnew = (-0.71, 0.71, 0)


Some relevant macros in transforms.inc:

vtransform(vec, trans)
Reorient_Trans(Axis1, Axis2)
Point_At_Trans(YAxis)

I don't have time to test this, but I think this will work:

   #include "transforms.inc"
   #declare P = <0, 1, 1>;
   #declare N = <-1, 0, 0>;
   #declare V = <0.71, 0.71, 0>;
   #declare Vnew = vtransform(V, Reorient_Trans(P, N));

This should also work:

   #include "transforms.inc"
   #declare N = <-1, 0, 0>;
   #declare V = <0.71, 0.71, 0>;
   #declare Vnew = vtransform(V, Point_At_Trans(N));

-- 
Tor Olav
http://subcube.com


Post a reply to this message

From: John VanSickle
Subject: Re: Vector calculation/rotation problem
Date: 16 Feb 2008 19:11:07
Message: <47b77b9b@news.povray.org>
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

From: Tor Olav Kristensen
Subject: Re: Vector calculation/rotation problem
Date: 16 Feb 2008 22:30:58
Message: <47b7aa72$1@news.povray.org>
Tor Olav Kristensen wrote:
> Severi Salminen wrote:
>> Severi Salminen wrote:
>>
>>> 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? 
>>
>> Example:
>>
>> V = (0.71, 0.71, 0) //The random vector in "northern hemishpere")
>> N = (-1,0,0) //The pole I want to orientate the random vectors to)
>>
>> The result is
>>
>> Vnew = (-0.71, 0.71, 0)
...

> I don't have time to test this, but I think this will work:
> 
>   #include "transforms.inc"
>   #declare P = <0, 1, 1>;
>   #declare N = <-1, 0, 0>;
>   #declare V = <0.71, 0.71, 0>;
>   #declare Vnew = vtransform(V, Reorient_Trans(P, N));
...

Hmmm... I wonder where I got the <0, 1, 1> vector from.
This is what I should have written:

   #include "transforms.inc"
   #declare P = <0, 1, 0>;
   #declare N = <-1, 0, 0>;
   #declare V = <0.71, 0.71, 0>;
   #declare Vnew = vtransform(V, Reorient_Trans(P, N));

-- 
Tor Olav
http://subcube.com


Post a reply to this message

From: Severi Salminen
Subject: Re: Vector calculation/rotation problem
Date: 17 Feb 2008 06:09:45
Message: <47b815f9@news.povray.org>
Thanks, but I'm actually interested in general solution without
resorting to functions provided by PovRay. As it is probably OT here,
I'll post the question to OT.


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Vector calculation/rotation problem
Date: 17 Feb 2008 19:53:12
Message: <47b8d6f8@news.povray.org>
Severi Salminen wrote:
> Thanks, but I'm actually interested in general solution without
> resorting to functions provided by PovRay. As it is probably OT here,
> I'll post the question to OT.

The code below is based on John's solution (but with some
simplifications). Most of the functions special to POV-Ray
has been replaced by common functions.

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.6;

#declare vN = <2, 1, 3>;
#declare SS = seed(6457);
#declare Cnt = 20;

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare vY =
   vN/sqrt(vN.x*vN.x + vN.y*vN.y + vN.z*vN.z);
#declare vX =
   <vY.z, 0, -vY.x>/sqrt(vY.x*vY.x + vY.z*vY.z);
#declare vZ =
   <vX.y*vY.z - vX.z*vY.y, vX.z*vY.x - vX.x*vY.z, vX.x*vY.y - vX.y*vY.x>;

cylinder { 0*y, vX, 0.03 pigment { color rgb <2, 1, 1> } }
cylinder { 0*y, vY, 0.03 pigment { color rgb <1, 2, 1> } }
cylinder { 0*y, vZ, 0.03 pigment { color rgb <1, 1, 2> } }

#declare I = 0;
#while (I < Cnt)
   #declare sN = rand(SS);
   #declare sL = sqrt(1 - sN*sN);
   #declare Angle = -2*pi*rand(SS);
   #declare vResult = sN*vY + sL*(cos(Angle)*vX + sin(Angle)*vZ);
   cylinder { 0*y, vResult, 0.01 pigment { color rgb <1, 1, 1> } }
   #declare I = I + 1;
#end // while

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

background { color rgb <0.0, 0.0, 0.5> }

light_source { <1, 1, 1>*100 color rgb <1, 1, 1> }

camera {
   location <3, 1, 2>
   look_at <0, 0, 0>
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


-- 
Tor Olav
http://subcube.com


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.