示例#1
0
 public static int compareLens(Lens l1, Lens l2)
 {
     if (l1.distance > l2.distance)
     {
         return(1);
     }
     else if (l1.distance < l2.distance)
     {
         return(-1);
     }
     else if (l1.isCurvatureRight && !l2.isCurvatureRight)
     {
         return(1);
     }
     else if (!l1.isCurvatureRight && l2.isCurvatureRight)
     {
         return(-1);
     }
     else
     {
         return(0);
     }
 }
示例#2
0
        private List <ResultSet> solve()
        {
            ParameterSet param;

            param = new ParameterSet();
            for (int i = 0; i < LensData.Count; i++)
            {
                if (LensData[i].isEnabled)
                {
                    Lens Lens = new Lens();
                    Lens.distance         = double.Parse(LensData[i].distance) * 1e-2;
                    Lens.curvature        = double.Parse(LensData[i].curvature) * 1e-2;
                    Lens.diameter         = double.Parse(LensData[i].diameter) * LensAnalyze.inch;
                    Lens.thickness        = double.Parse(LensData[i].thickness) * 1e-3;
                    Lens.refractiveIndex  = double.Parse(LensData[i].refractiveIndex);
                    Lens.isCurvatureRight = LensData[i].isCurvatureRight;
                    Lens.diameter         = Math.Min(Lens.curvature * 2, Lens.diameter);
                    param.Lenss.Add(Lens);
                }
            }
            if (param.Lenss.Count <= 0)
            {
                throw new Exception();
            }
            double opticalMaxDistance = maxDistance;
            double opticalMinDistance = minDistance;

            for (int i = 0; i < param.Lenss.Count; i++)
            {
                double cuv = param.Lenss[i].curvature;
                double rad = param.Lenss[i].radius;
                double thi = param.Lenss[i].thickness;
                double pos = param.Lenss[i].distance;
                double dif = Math.Abs(cuv) - Math.Sqrt(cuv * cuv - rad * rad);
                double rf = param.Lenss[i].refractiveIndex;
                double left, right;
                if (param.Lenss[i].isCurvatureRight && param.Lenss[i].curvature > 0)
                {
                    left = pos; right = pos + thi + dif;
                }
                else if (!param.Lenss[i].isCurvatureRight && param.Lenss[i].curvature > 0)
                {
                    left = pos - dif - thi; right = pos;
                }
                else if (param.Lenss[i].isCurvatureRight && !(param.Lenss[i].curvature > 0))
                {
                    left = pos; right = pos + thi - dif;
                }
                else
                {
                    left = pos - thi + dif; right = pos;
                }
                if (left < minDistance && minDistance < right)
                {
                    opticalMinDistance += (minDistance - left) * (rf - LensAnalyze.airRefractiveIndex);
                }
                if (right < minDistance)
                {
                    opticalMinDistance += (right - left) * (rf - LensAnalyze.airRefractiveIndex);
                }
                if (left < maxDistance && maxDistance < right)
                {
                    opticalMaxDistance += (maxDistance - left) * (rf - LensAnalyze.airRefractiveIndex);
                }
                if (right < maxDistance)
                {
                    opticalMaxDistance += (right - left) * (rf - LensAnalyze.airRefractiveIndex);
                }
            }
            for (int j = 0; j < waveCount; j++)
            {
                param.time.Add(opticalMaxDistance / LensAnalyze.vc + (opticalMaxDistance - opticalMinDistance) / LensAnalyze.vc * j / (waveCount - 1));
            }

            clearPaint();
            paintCommon(param);
            List <ResultSet> ress = new List <ResultSet>();

            for (int orgc = 0; orgc < originData.Count; orgc++)
            {
                if (originData[orgc].isEnabled)
                {
                    param.origin            = new Origin();
                    param.origin.position   = double.Parse(originData[orgc].position) * 1e-2;
                    param.origin.height     = double.Parse(originData[orgc].height) * 1e-3;
                    param.origin.wavelength = double.Parse(originData[orgc].wavelength) * 1e-9;

                    double divergence = double.Parse(originData[orgc].divergence);
                    maxAngle = divergence;
                    minAngle = -divergence;
//					maxAngle = Math.Atan((1.0 + atomHeight / LensAnalyze.inch) * Math.Tan(inputAngle));
//					minAngle = -Math.Atan((1.0 - atomHeight / LensAnalyze.inch) * Math.Tan(inputAngle));
//					maxAngle = Math.Atan((param.Lenss[0].radius-atomHeight) / param.Lenss[0].distance);
//					minAngle = Math.Atan((-param.Lenss[0].radius-atomHeight) / param.Lenss[0].distance);
                    param.theta.Clear();
                    for (int j = 0; j < rayCount; j++)
                    {
                        param.theta.Add(minAngle + (maxAngle - minAngle) * j / (rayCount - 1));
                    }

                    if (rayCount == 0 || waveCount == 0)
                    {
                        continue;
                    }
//					double inputAngle = Math.Atan(LensAnalyze.inputLensDiameter / 2 / inputFocalLength);

                    ResultSet res;
                    if (CheckBox_CalcMethod.IsChecked.Value)
                    {
                        res = (new LensAnalyze()).solveAbberation(param);
                    }
                    else
                    {
                        res = (new LensAnalyze()).solveSimplest(param);
                    }
                    int   colori = Convert.ToInt32(originData[orgc].color, 16);
                    byte  r      = (byte)(colori % 0x100);
                    byte  g      = (byte)((colori / 0x100) % 0x100);
                    byte  b      = (byte)((colori / 0x100 / 0x100) % 0x100);
                    Color color  = new Color {
                        R = r, G = g, B = b
                    };
                    paintResult(param, res, color);
                    ress.Add(res);
                }
            }
            return(ress);
        }