You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Alexander Nozik <al...@gmail.com> on 2013/07/08 14:44:29 UTC

[math] Rotation around given direction

  In order to solve some Monte-Carlo problem I need to implement the 
following procedure: during interaction I know the difference between 
the initial and the final angle "dTheta" (the direction is random) and 
the initial polar angle "theta" (using notation like here 
http://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates). 
What i need to know is the final polar angle. Azimuthal angle does not 
matter.
In order to do so I am creating two vectors with polar angles "theta" 
and "theta + dTheta" and trying to rotate one around the other for a 
random angle "phi" (phi could be fixed as well, it does not matter). 
What i don't understand is why the angle between the final vector and 
the initial one is not "dTheta"?

I use the following code:

    double addTheta(double theta, double dTheta) {
         double phi = generator.next() * 2 * Math.PI;
         SphericalCoordinates init = new SphericalCoordinates(1, 0, 
theta+dTheta);
         SphericalCoordinates rotate = new SphericalCoordinates(1, 0, 
theta);
         Rotation rot = new Rotation(rotate.getCartesian(), phi);

         Vector3D result = rot.applyTo(init.getCartesian());

         assert Vector3D.angle(result, init.getCartesian()) == dTheta;
         return Math.acos(result.getZ());

     }

Thanks in advance.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [math] Rotation around given direction

Posted by Luc Maisonobe <Lu...@free.fr>.
Hi Alexander,

Le 08/07/2013 14:44, Alexander Nozik a écrit :
>  In order to solve some Monte-Carlo problem I need to implement the
> following procedure: during interaction I know the difference between
> the initial and the final angle "dTheta" (the direction is random) and
> the initial polar angle "theta" (using notation like here
> http://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates).
> What i need to know is the final polar angle. Azimuthal angle does not
> matter.
> In order to do so I am creating two vectors with polar angles "theta"
> and "theta + dTheta" and trying to rotate one around the other for a
> random angle "phi" (phi could be fixed as well, it does not matter).
> What i don't understand is why the angle between the final vector and
> the initial one is not "dTheta"?
> 
> I use the following code:
> 
>    double addTheta(double theta, double dTheta) {
>         double phi = generator.next() * 2 * Math.PI;
>         SphericalCoordinates init = new SphericalCoordinates(1, 0,
> theta+dTheta);
>         SphericalCoordinates rotate = new SphericalCoordinates(1, 0,
> theta);
>         Rotation rot = new Rotation(rotate.getCartesian(), phi);
> 
>         Vector3D result = rot.applyTo(init.getCartesian());
> 
>         assert Vector3D.angle(result, init.getCartesian()) == dTheta;

The angle that should be equalt to dTheta is the angle between result
and rotate.getCartesian(), not the angle between result and
init.getCartesian(). The latter can take any value between 0 and 2 * dTheta.

best regards,
Luc

>         return Math.acos(result.getZ());
> 
>     }
> 
> Thanks in advance.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org