A vertex is a simple class that stores the postion of a point, node or vertex.
Inheritance: System.Windows.Shapes.Shape, IVertex
Exemple #1
0
        private void btnMakePoints_Click(object sender, RoutedEventArgs e)
        {
            drawingCanvas.Children.Clear();
            var sizeX = drawingCanvas.ActualWidth;
            var sizeY = drawingCanvas.ActualHeight;
            vertices = new List<Vertex>();
            var r = new Random();

            /****** Random Vertices ******/
            for (var i = 0; i < NumberOfVertices; i++)
            {
                var vi = new Vertex(sizeX * r.NextDouble(), sizeY * r.NextDouble());
                vertices.Add(vi);
            }
            
            ShowVertices();

            var now = DateTime.Now;
            voronoiMesh = VoronoiMesh.Create<Vertex, Cell>(vertices);
            var interval = DateTime.Now - now;
            txtBlkTimer.Text = string.Format("{0:0.000}s ({1} faces)", interval.TotalSeconds, voronoiMesh.Vertices.Count());

            btnFindDelaunay.IsEnabled = true;
            btnFindVoronoi.IsEnabled = true;
        }
        private void btnMakeCirclePoints_Click(object sender, RoutedEventArgs e)
        {
            ClearAndDrawAxes();
            vertices = new List<Vertex>();
            var r = new Random();

            /****** Random Vertices ******/
            for (var i = 0; i < NumberOfVertices; i++)
            {
                var radius = size + r.NextDouble();
                // if (i < NumberOfVertices / 2) radius /= 2;
                var theta = 2 * Math.PI * r.NextDouble();
                var azimuth = Math.PI * r.NextDouble();
                var x = radius * Math.Cos(theta) * Math.Sin(azimuth);
                var y = radius * Math.Sin(theta) * Math.Sin(azimuth);
                var z = radius * Math.Cos(azimuth);
                var vi = new Vertex(x, y, z);
                vertices.Add(vi);
                /*
                 *          do {
                 x1 = 2.0 * ranf() - 1.0;
                 x2 = 2.0 * ranf() - 1.0;
                 w = x1 * x1 + x2 * x2;
             } while ( w >= 1.0 );

             w = sqrt( (-2.0 * ln( w ) ) / w );
             y1 = x1 * w;
             y2 = x2 * w;

                 */

                viewport.Children.Add(vi);
            }
            btnRun.IsDefault = true;
            txtBlkTimer.Text = "00:00:00.000";
        }
        private void btnMakeRegularPoints_Click(object sender, RoutedEventArgs e)
        {
            ClearAndDrawAxes();
            vertices = new List<Vertex>();
            var r = new Random();

            for (int i = 0; i <= 10; i++)
            {
                for (int j = 0; j <= 10; j++)
                {
                    for (int k = 0; k <= 10; k++)
                    {
                        var v = new Vertex(-20 + 4 * i, -20 + 4 * j, -20 + 4 * k);
                        vertices.Add(v);
                        viewport.Children.Add(v);
                    }
                }
            }

            btnRun.IsDefault = true;
            txtBlkTimer.Text = "00:00:00.000";
        }
        private void btnMakeSquarePoints_Click(object sender, RoutedEventArgs e)
        {
            ClearAndDrawAxes();
            vertices = new List<Vertex>();
            var r = new Random();

            /****** Random Vertices ******/
            for (var i = 0; i < NumberOfVertices; i++)
            {
                var vi = new Vertex(size * r.NextDouble() - size / 2, size * r.NextDouble() - size / 2,
                                    size * r.NextDouble() - size / 2);
                vertices.Add(vi);
                viewport.Children.Add(vi);
            }

            btnRun.IsDefault = true;
            txtBlkTimer.Text = "00:00:00.000";
        }
 void MakeRandom(int n, List<Vertex> vertices)
 {
     var r = new Random();
     var sizeX = drawingCanvas.ActualWidth;
     var sizeY = drawingCanvas.ActualHeight;
     for (var i = 0; i < n; i++)
     {
         var vi = new Vertex(sizeX * r.NextDouble(), sizeY * r.NextDouble());
         vertices.Add(vi);
     }
 }
 void MakeGrid(int n, List<Vertex> vertices)
 {
     var sizeX = drawingCanvas.ActualWidth;
     var sizeY = drawingCanvas.ActualHeight;
     for (int i = 0; i < n; i++)
     {
         for (int j = 0; j < n; j++)
         {
             var vi = new Vertex(i * sizeX / (n - 1), j * sizeY / (n - 1));
             vertices.Add(vi);
         }
     }
 }