public void generate_random_points(int inpt_point_count, int x_coord_limit, int y_coord_limit) { delaunay_triangle = new Planar_object_store(); // reinitialize the all the lists List <Planar_object_store.point2d> temp_pt_list = new List <Planar_object_store.point2d>(); // create a temporary list to store the points // !!!!!!!!!!!! Need major improvements below - very slow to generate unique n random points !!!!!!!!!!!!!!!!!!!!!!!!!!! int point_count = inpt_point_count; do { for (int i = 0; i < point_count; i++) // Loop thro' the point count { Planar_object_store.point2d temp_pt; // temp_pt to store the intermediate random points PointF rand_pt = new PointF(rand0.Next(-x_coord_limit, x_coord_limit), rand0.Next(-y_coord_limit, y_coord_limit)); temp_pt = new Planar_object_store.point2d(i, rand_pt.X, rand_pt.Y); temp_pt_list.Add(temp_pt); // add to the temp list } temp_pt_list = temp_pt_list.Distinct(new Planar_object_store.points_equality_comparer()).ToList(); point_count = inpt_point_count - temp_pt_list.Count; } while (point_count != 0); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // copy to the main list delaunay_triangle.delaunay_points = temp_pt_list; // List<PointF> temp_rand_pts = Enumerable.Range(0,point_count).Select(obj => the_static_class.random_point(-x_coord_limit, x_coord_limit,-y_coord_limit, y_coord_limit)).ToList(); }
private void button_lloyds_Click(object sender, EventArgs e) { // Lloyd's relaxation if (iteration > 0) { while (iteration < 20) { int x_coord_limit = (int)(the_static_class.canvas_size.Width * 0.5); int y_coord_limit = (int)(the_static_class.canvas_size.Height * 0.5); delaunay_triangle.delaunay_points = new List <Planar_object_store.point2d>(); // Delaunay Boundary points int pt_id = delaunay_triangle.delaunay_points.Count; foreach (Planar_object_store.polygon2d poly in delaunay_triangle.voronoi_polygon) { Planar_object_store.point2d pt = new Planar_object_store.point2d(pt_id, poly.mid_pt.x, poly.mid_pt.y); delaunay_triangle.delaunay_points.Add(pt); pt_id++; } // start of the delaunay triangulation delaunay_triangle.delaunay_edges = new List <Planar_object_store.edge2d>(); // reinitialize the edge lists delaunay_triangle.delaunay_faces = new List <Planar_object_store.face2d>(); delaunay_triangle.voronoi_points = new List <Planar_object_store.point2d>(); delaunay_triangle.voronoi_edges = new List <Planar_object_store.edge2d>(); delaunay_triangle.voronoi_polygon = new List <Planar_object_store.polygon2d>(); List <Planar_object_store.edge2d> temp_edges = new List <Planar_object_store.edge2d>(); List <Planar_object_store.face2d> temp_faces = new List <Planar_object_store.face2d>(); List <Planar_object_store.point2d> temp_v_points = new List <Planar_object_store.point2d>(); List <Planar_object_store.edge2d> temp_v_edges = new List <Planar_object_store.edge2d>(); List <Planar_object_store.polygon2d> temp_v_polygons = new List <Planar_object_store.polygon2d>(); // Delaunay Triangulation and voronoi tesselation (new delaunay_triangulation_divide_n_conquer()).delaunay_start(delaunay_triangle.delaunay_points, x_coord_limit, y_coord_limit, ref temp_edges, ref temp_faces, ref temp_v_points, ref temp_v_edges, ref temp_v_polygons); delaunay_triangle.delaunay_edges = temp_edges; delaunay_triangle.delaunay_faces = temp_faces; delaunay_triangle.voronoi_points = temp_v_points; delaunay_triangle.voronoi_edges = temp_v_edges; delaunay_triangle.voronoi_polygon = temp_v_polygons; iteration++; mt_pic.Refresh();// Refresh the paint region } iteration = 2; } }