Exemplo n.º 1
0
        public static SHResult AFToSH(double[,] r, IList <float> mu, IList <float> phi, int n, IList <double> gaussWeights = null, IList <double[][]> qkm = null)
        {
            // mu задано в нулях полиномов Лежандра

            if (gaussWeights == null)
            {
                gaussWeights = Legzo(mu.Count).Weight;
            }

            if (qkm == null)
            {
                qkm = new List <double[][]>();
                foreach (var m in mu)
                {
                    qkm.Add(Schmidt(m, n));
                }
            }

            var dphi = (float)(2 * Math.PI / (phi.Count - 1));

            var result = new SHResult(n);

            for (int k = 0; k < n; k++)
            {
                float ksi = 1;
                float k2  = 2 * k + 1;

                for (int m = 0; m < k + 1; m++)
                {
                    float a = 0;
                    float b = 0;

                    for (int imu = 0; imu < mu.Count; imu++)
                    {
                        var w = (float)gaussWeights[imu];

                        for (int iphi = 0; iphi < phi.Count; iphi++)
                        {
                            float wi = (iphi == 0 || iphi == phi.Count - 1) ? 0.5f : 1f;

                            a = a + ksi * (float)(Math.Cos(m * phi[iphi]) * r[imu, iphi] * qkm[imu][k][m] * k2 * wi * w);
                            b = b + ksi * (float)(Math.Sin(m * phi[iphi]) * r[imu, iphi] * qkm[imu][k][m] * k2 * wi * w);
                        }
                    }

                    result.A[k][m] = a * dphi * 0.25f / (float)Math.PI;
                    result.B[k][m] = b * dphi * 0.25f / (float)Math.PI;
                    if (m == 0)
                    {
                        ksi = ksi * 2;
                    }
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        public static float[][] SHToAF(SHResult sh, IList <float> mu, IList <float> phi, IList <double[][]> qkm = null)
        {
            var result = new float[mu.Count][];

            for (int i = 0; i < mu.Count; i++)
            {
                result[i] = new float[phi.Count];
            }

            if (qkm == null)
            {
                qkm = new List <double[][]>();
                foreach (var m in mu)
                {
                    qkm.Add(Schmidt(m, sh.N));
                }
            }

            for (int imu = 0; imu < mu.Count; imu++)
            {
                for (int iphi = 0; iphi < phi.Count; iphi++)
                {
                    double r = 0;
                    for (int k = 0; k < sh.N; k++)
                    {
                        for (int m = 0; m < k + 1; m++)
                        {
                            r += qkm[imu][k][m] * (sh.A[k][m] * Math.Cos(m * phi[iphi]) + sh.B[k][m] * Math.Sin(m * phi[iphi]));
                        }
                    }

                    result[imu][iphi] = (float)r;
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        public static float SHToAF(SHResult sh, float mu, float phi, double[][] qkm = null)
        {
            /*
             * var result = new float[mu.Count][];
             * for ( int i = 0; i < mu.Count; i++ )
             *  result[i] = new float[phi.Count];
             */
            if (qkm == null)
            {
                qkm = Schmidt(mu, sh.N);
            }

            double r = 0;

            for (int k = 0; k < sh.N; k++)
            {
                for (int m = 0; m < k + 1; m++)
                {
                    r += qkm[k][m] * (sh.A[k][m] * Math.Cos(m * phi) + sh.B[k][m] * Math.Sin(m * phi));
                }
            }

            return((float)r);
        }