Esempio n. 1
0
        /// <summary>
        /// 计算小球的半径
        /// 小球的半径的最大值 Rmax = 0.5
        /// 此处设置的是均匀随机分布,小球半径符合还可能符合对数正态分布等
        /// </summary>
        /// <returns></returns>
        private double ComputeRandomRadius(RandomType type)
        {
            //小球的半径是:[0.5-MaxRadiusBias ~ 0.5]*Rmax/0.5
            double radius = 0.0;

            switch (type)
            {
            case RandomType.AverageRandomType:
                radius = GenerateRandomNumber.AverageRandom(0.5 - MaxRadiusBias, 0.5);
                break;

            case RandomType.RandomLogNormalType:
                //第一批样品30~50um的的参数
                double maxD  = ActualSampleParameter.ActualSampleParaDict[PackingSystemSetting.ParticleSizeType].MaxDiameter;
                double minD  = ActualSampleParameter.ActualSampleParaDict[PackingSystemSetting.ParticleSizeType].MinDiameter;
                double sigma = ActualSampleParameter.ActualSampleParaDict[PackingSystemSetting.ParticleSizeType].LogSigma;
                double miu   = ActualSampleParameter.ActualSampleParaDict[PackingSystemSetting.ParticleSizeType].LogMiu;
                MaxRadiusBias = (1 - minD / maxD) / 2;

                double reso = MaxRadius / (maxD / 2);
                radius = GenerateRandomNumber.RandomLogNormal(miu,
                                                              sigma,
                                                              minD,
                                                              maxD) / 2;
                radius = radius * reso;

                break;

            case RandomType.RandomNormalType:
                break;
            }
            return(radius);
        }
        /// <summary>
        ///产生均匀随机分布的随机数测试
        /// </summary>
        public static void TestAverageRandomNumber()
        {
            int             num = 10000;
            double          min = 1e-5;
            double          max = 3e-5;
            Matrix <double> m   = new Matrix <double>(num, 1);

            for (int i = 0; i < num; i++)
            {
                m[i, 0] = GenerateRandomNumber.AverageRandom(min, max);
            }
            Emgu.CV.Structure.MCvScalar s = CvInvoke.Mean(m);
            Console.WriteLine("random average number generation: min is {0}, max is {1}, average is {2}", min, max, s.V0);
        }