![]() ![]() ![]() ![]() |
|||||
|
|||||
樓主 ttt ![]()
![]() |
//负责画左边的坐标和数据点 protected override void OnPaint(PaintEventArgs e) { Graphics graphics = e.Graphics; Pen pen = new Pen(Color.Black, 1); Brush text_brush = new SolidBrush(Color.Black); Font text_font = new Font("宋体", 14); //x graphics.DrawLine(pen, Center_Zero_X, Center_Zero_Y, Center_Zero_X + LineLength, Center_Zero_Y);//x横线 graphics.DrawLine(pen, Center_Zero_X + LineLength - 5, Center_Zero_Y - 5, Center_Zero_X + LineLength, Center_Zero_Y);//x graphics.DrawLine(pen, Center_Zero_X + LineLength - 5, Center_Zero_Y + 5, Center_Zero_X + LineLength, Center_Zero_Y);//x graphics.DrawString("X", text_font, text_brush, Center_Zero_X + LineLength, Center_Zero_Y - 10); //y graphics.DrawLine(pen, Center_Zero_X, Center_Zero_Y, Center_Zero_X, Center_Zero_Y - LineLength);//y竖向线 graphics.DrawLine(pen, Center_Zero_X - 5, Center_Zero_Y - LineLength + 5, Center_Zero_X, Center_Zero_Y - LineLength);//y竖向线 graphics.DrawLine(pen, Center_Zero_X + 5, Center_Zero_Y - LineLength + 5, Center_Zero_X, Center_Zero_Y - LineLength);//y竖向线 graphics.DrawString("Y", text_font, text_brush, Center_Zero_X, Center_Zero_Y - LineLength + 10); //0 Pen point_pen = new Pen(Color.Black, 2); foreach (DataPoint dp in Dbscan.DataPoints_arry) { if (dp != null) { if (dp.cluster_tag == 0) point_pen.Color = Color.Black; else point_pen.Color = GetColor(dp.cluster_tag); graphics.DrawEllipse(point_pen, (float)dp.d1, (float)dp.d2, 2, 1); } } #region Windows 画凹包 if (reset && convexhull_checkbox.Checked) { int size = Dbscan.clustet_set.Count; int num = 0; for (int i = 0; i < size; i++) { int count = ((ArrayList)Dbscan.clustet_set[i]).Count; Console.WriteLine("count " + i + " , n=" + count); num += count; ArrayList subArray = (ArrayList)Dbscan.clustet_set[i]; Color clusterColor = GetColor(((DataPoint)subArray[0]).cluster_tag); Points p = new Points(); for (int j = 0; j < count; j++) { p.Add(new CGPoint(((DataPoint)subArray[j]).d1, ((DataPoint)subArray[j]).d2)); } if (p.Count > 3) { Console.WriteLine("big thank 3"); Points convexPoint = new Points(); convexHull = new ConvexHull(p); convexPoint = convexHull.GetConvexHull(); PointF[] pointf; pointf = new PointF[convexPoint.Count]; for (int k = 0; k < convexPoint.Count; k++) { pointf[k] = new PointF(convexPoint[k].X, convexPoint[k].Y); } Pen bluePen = new Pen(clusterColor, 2); graphics.DrawPolygon(bluePen, pointf); } } reset = false; Console.WriteLine("the num=" + num); } #endregion } //根据index,返回不同类的颜色,用于区分不同的族.最大支持16种不同颜色 public Color GetColor(int index) { Color[] xColor ={ Color.Red , Color.Pink, Color.Green, Color.Gold, Color.Purple, Color.Blue, Color.Orange, Color.Plum ,Color.Cyan,Color.GreenYellow,Color.LightBlue, Color.MediumSpringGreen,Color.PowderBlue,Color.SlateBlue}; return xColor[index % xColor.Length]; }
搜尋相關Tags的文章:
[ Windows Forms轉成WPF ] ,
本篇文章發表於2018-06-03 08:56 |