Rotate() public method

public Rotate ( Vector3 &_Axis, double _Angle, Vector3 &_Out ) : void
_Axis Vector3
_Angle double
_Out Vector3
return void
示例#1
0
        public static void std_coords_to_half_diff_coords(double _ThetaIn, double _PhiIn, double _ThetaOut, double _PhiOut,
                                                          out double _ThetaHalf, out double _PhiHalf, out double _ThetaDiff, out double _PhiDiff)
        {
            // compute in vector
            double in_vec_z    = Math.Cos(_ThetaIn);
            double proj_in_vec = Math.Sin(_ThetaIn);
            double in_vec_x    = proj_in_vec * Math.Cos(_PhiIn);
            double in_vec_y    = proj_in_vec * Math.Sin(_PhiIn);

            In.Set(in_vec_x, in_vec_y, in_vec_z);

            // compute out vector
            double out_vec_z    = Math.Cos(_ThetaOut);
            double proj_out_vec = Math.Sin(_ThetaOut);
            double out_vec_x    = proj_out_vec * Math.Cos(_PhiOut);
            double out_vec_y    = proj_out_vec * Math.Sin(_PhiOut);

            Out.Set(out_vec_x, out_vec_y, out_vec_z);

            // compute halfway vector
            Half.Set(in_vec_x + out_vec_x, in_vec_y + out_vec_y, in_vec_z + out_vec_z);
            Half.Normalize();

            // compute  _ThetaHalf, _PhiHalf
            _ThetaHalf = Math.Acos(Half.z);
            _PhiHalf   = Math.Atan2(Half.y, Half.x);

            // Compute diff vector
            In.Rotate(ref Normal, -_PhiHalf, out Temp);
            Temp.Rotate(ref BiTangent, -_ThetaHalf, out Diff);

            // Compute _ThetaDiff, _PhiDiff
            _ThetaDiff = Math.Acos(Math.Min(1.0, Diff.z));
            _PhiDiff   = Math.Atan2(Diff.y, Diff.x);
        }
示例#2
0
        public static void      half_diff_coords_to_std_coords(double _ThetaHalf, double _PhiHalf, double _ThetaDiff, double _PhiDiff,
                                                               out double _ThetaIn, out double _PhiIn, out double _ThetaOut, out double _PhiOut)
        {
            double SinTheta_half = Math.Sin(_ThetaHalf);

            Half.Set(Math.Cos(_PhiHalf) * SinTheta_half, Math.Sin(_PhiHalf) * SinTheta_half, Math.Cos(_ThetaHalf));

            // Build the 2 vectors representing the frame in which we can use the diff angles
            Vector3 OrthoX;

            Half.Cross(ref Normal, out OrthoX);
            if (OrthoX.LengthSq() < 1e-6)
            {
                OrthoX.Set(1, 0, 0);
            }
            else
            {
                OrthoX.Normalize();
            }

            Vector3 OrthoY;

            Half.Cross(ref OrthoX, out OrthoY);

            // Rotate using diff angles to retrieve incoming direction
            Half.Rotate(ref OrthoX, -_ThetaDiff, out Temp);
            Temp.Rotate(ref Half, _PhiDiff, out In);

            // We can get the outgoing vector either by rotating the incoming vector half a circle
//          Temp.Rotate( ref Half, _PhiDiff + Math.PI, out Out );

            // ...or by mirroring in "Half tangent space"
            double MirrorX = -In.Dot(ref OrthoX);
            double MirrorY = -In.Dot(ref OrthoY);
            double z       = In.Dot(ref Half);

            Out.Set(
                MirrorX * OrthoX.x + MirrorY * OrthoY.x + z * Half.x,
                MirrorX * OrthoX.y + MirrorY * OrthoY.y + z * Half.y,
                MirrorX * OrthoX.z + MirrorY * OrthoY.z + z * Half.z
                );

            // CHECK
//          Vector3	CheckHalf = new Vector3() { x = In.x+Out.x, y = In.y+Out.y, z = In.z+Out.z };
//                  CheckHalf.Normalize();	// Is this Half ???
            // CHECK

            // Finally, we can retrieve the angles we came here to look for...
            _ThetaIn  = Math.Acos(In.z);
            _PhiIn    = Math.Atan2(In.y, In.x);
            _ThetaOut = Math.Acos(Out.z);
            _PhiOut   = Math.Atan2(Out.y, Out.x);
        }