示例#1
0
        public Variance VarianceOf(Geodesic geodesic)
        {
            List <double> areas     = new List <double>();
            double        totalArea = 0;
            double        maxArea   = -10;
            double        minArea   = 10;

            double lengthMin   = 10;
            double lengthMax   = 0;
            double lengthTotal = 0;

            for (int i = 0; i < geodesic.MaxGridIndex; i++)
            {
                GridIndex            index    = geodesic.GetGridIndex(i);
                GeodesicGridTriangle triangle = index.GeodesicGridTriangle;
                double area = triangle.Area;
                areas.Add(area);
                totalArea += area;
                if (area > maxArea)
                {
                    maxArea = area;
                }
                if (area < minArea)
                {
                    minArea = area;
                }

                double a = (triangle.PointCA - triangle.PointAB).Magnitude;
                double b = (triangle.PointAB - triangle.PointBC).Magnitude;
                double c = (triangle.PointBC - triangle.PointCA).Magnitude;

                double maxLength = a > b ? a > c ? a : c : b > c ? b : c;
                double minLength = a < b ? a < c ? a : c : b < c ? b : c;
                if (maxLength > lengthMax)
                {
                    lengthMax = maxLength;
                }
                if (minLength < lengthMin)
                {
                    lengthMin = minLength;
                }

                lengthTotal += a + b + c;
            }
            Variance variance = new Variance();

            variance.variance = maxArea / minArea;

            variance.max     = maxArea;
            variance.min     = minArea;
            variance.average = totalArea / geodesic.MaxGridIndex;

            variance.lengthMin     = lengthMin;
            variance.lengthMax     = lengthMax;
            variance.lengthAverage = lengthTotal / geodesic.MaxGridIndex / 3;

            return(variance);
        }
示例#2
0
        /*
         * private void DownShiftBox_Click(object sender, EventArgs e)
         * {
         * ShiftBox.Text = (Convert.ToDouble(ShiftBox.Text) / 2).ToString();
         * }
         *
         * private void UpShiftBox_Click(object sender, EventArgs e)
         * {
         * ShiftBox.Text = (Convert.ToDouble(ShiftBox.Text) * 2).ToString();
         * }
         *
         * private void UpButton_Click(object sender, EventArgs e)
         * {
         * VarianceBox.Text = (Convert.ToDouble(VarianceBox.Text) + Convert.ToDouble(ShiftBox.Text)).ToString();
         * }
         *
         * private void DownButton_Click(object sender, EventArgs e)
         * {
         * VarianceBox.Text = (Convert.ToDouble(VarianceBox.Text) - Convert.ToDouble(ShiftBox.Text)).ToString();
         * }*/

        /*
         * private void VarianceBox_TextChanged(object sender, EventArgs e)
         * {
         * try
         * {
         *  Vector3D projectionPoint = Geodesic.DefaultProjectionPoint * new Equation(Convert.ToDouble(VarianceBox.Text),"Custom");
         *  Geodesic geodesic = new Geodesic(0, projectionPoint);
         *  Equation variance = VarianceOf(geodesic);
         *  VarianceLabel.Text = variance.ToString();
         * }
         * catch
         * {
         *
         * }
         * }*/

        /// <summary>
        /// Calculate the area variance for both bisect and new geodesic grid for each generation up to the given one.
        /// This is put in a csv file.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void VarianceButton_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog sfd = new SaveFileDialog()
            {
                Filter = "*.csv|*.csv"
            })
            {
                if (sfd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                List <string> result = new List <string>();
                result.Add("generation,bisect min,bisect max, bisect average, projection point min, projection point max, projection point average," +
                           "bisect length min, bisect length max, bisect length average, projection length min, projection length max, projection length average");



                int maxGeneration = Convert.ToInt32(GenerationBox.Text);

                for (int generation = 1; generation <= maxGeneration; generation++)
                {
                    BisectGeodesicLowMemory bisectGeodesic = new BisectGeodesicLowMemory(generation);
                    double min   = 10;
                    double max   = 0;
                    double total = 0;

                    double lengthMin   = 10;
                    double lengthMax   = 0;
                    double lengthTotal = 0;
                    //foreach (SphericalTriangle triangle in bisectGeodesic.SphericalTriangles)
                    for (int i = 0; i < bisectGeodesic.TriangleCount; i++)
                    {
                        SphericalTriangle triangle = bisectGeodesic.GetTriangle(i);
                        double            area     = triangle.Area;
                        if (area < min)
                        {
                            min = area;
                        }
                        if (area > max)
                        {
                            max = area;
                        }
                        total += area;
                        double ab        = (triangle.A - triangle.B).Magnitude;
                        double bc        = (triangle.B - triangle.C).Magnitude;
                        double ca        = (triangle.C - triangle.A).Magnitude;
                        double maxLength = ab > bc ? ab > ca ? ab : ca : bc > ca ? bc : ca;
                        double minLength = ab < bc ? ab < ca ? ab : ca : bc < ca ? bc : ca;
                        if (maxLength > lengthMax)
                        {
                            lengthMax = maxLength;
                        }
                        if (minLength < lengthMin)
                        {
                            lengthMin = minLength;
                        }
                        lengthTotal += ab + bc + ca;
                    }
                    double   average           = total / bisectGeodesic.TriangleCount;
                    double   averageLength     = lengthTotal / bisectGeodesic.TriangleCount / 3;
                    double   bisectVariance    = max / min;
                    Geodesic geodesic          = new Geodesic(generation - 2);
                    Variance geodesicViariance = VarianceOf(geodesic);
                    result.Add(generation.ToString() + "," + min.ToString() + "," + max.ToString() + "," + average.ToString() +
                               "," + geodesicViariance.min.ToString() + "," + geodesicViariance.max.ToString() + "," + geodesicViariance.average.ToString() + "," +
                               lengthMin.ToString() + "," + lengthMax.ToString() + "," + averageLength.ToString() + "," +
                               geodesicViariance.lengthMin.ToString() + "," + geodesicViariance.lengthMax.ToString() + "," + geodesicViariance.lengthAverage.ToString()
                               );
                }
                File.WriteAllLines(sfd.FileName, result);
            }
        }