• 大小: 127KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-01
  • 语言: C#
  • 标签: kmeans  聚类,C#  

资源简介

具有图形界面,支持界面画点和随机生成散点,界面较友好

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace KMeans
{
    public partial class MainFrm : Form
    {
        //全局变量
        List Points = new List();                     //点
        List CenterPoints = new List();   //质心点(簇的个数)

        //历史记录
        int iIdx = 0;      //序号
        int iTime = 0;      //轮数
        List> PointsHistory = new List>();
        List> CenterPointsHistory = new List>();



        public MainFrm()
        {
            InitializeComponent();
        }

        private void MainFrm_Activated(object sender EventArgs e)
        {
            btnRandom.Focus();
        }


        #region 辅助函数----------------------------------------------------------------------------------------------------------------------------------

        /// 
        /// 画点
        /// 

        /// 
        private void DrawPoints(PaintEventArgs e)
        {
            Graphics graphic = e.Graphics;
            graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            int offSet = 3;
            for (int i = 0; i < Points.Count; i++)
            {
                Point pPoint = Points[i];
                System.Drawing.Point newPoint = new System.Drawing.Point(pPoint.x pPoint.y);
                graphic.DrawEllipse(new Pen(System.Drawing.Color.Black 1) newPoint.X - offSet newPoint.Y - offSet 2 * offSet 2 * offSet);      //画点

                //if (pointToDraw.group >= 0)    //如果属于聚类,画标号
                //{
                //    graphic.DrawString((pointToDraw.group + 1).ToString() new System.Drawing.Font(“Arial“ 10) System.Drawing.Brushes.Brown newPoint.X + 8 newPoint.Y - 8);
                //}
            }
        }

        /// 
        /// 画质心,并与它一类点的虚线
        /// 

        /// 
        private void DrawCenter(PaintEventArgs e)
        {
            //绘制对象
            Graphics graphic = e.Graphics;
            graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            //画笔
            Pen pPen = new Pen(System.Drawing.Color.Red 1);
            pPen.Dashstyle = System.Drawing.Drawing2D.Dashstyle.Custom;
            pPen.DashPattern = new float[] { 1 1 };

            for (int i = 0; i < CenterPoints.Count; i++)    //循环质心
            {
                CenterPoint pCenter = CenterPoints[i];

                //画质心到其他点的虚线
                for (int j = 0; j < Points.Count; j++)
                {
                    Point pPoint = (Point)Points[j];
                    if (pPoint.group == i)
                    {
                        System.Drawing.Point p1 = new System.Drawing.Point(pCenter.x pCenter.y);
                        System.Drawing.Point p

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      22528  2014-10-11 09:41  KMeans\KMeans\bin\Debug\KMeans.exe

     文件      48640  2014-10-11 09:41  KMeans\KMeans\bin\Debug\KMeans.pdb

     文件      22704  2015-01-04 18:03  KMeans\KMeans\bin\Debug\KMeans.vshost.exe

     文件        490  2013-03-18 17:00  KMeans\KMeans\bin\Debug\KMeans.vshost.exe.manifest

     文件      21504  2014-10-15 07:10  KMeans\KMeans\bin\Release\KMeans.exe

     文件      46592  2014-10-15 07:10  KMeans\KMeans\bin\Release\KMeans.pdb

     文件      22704  2014-10-15 07:10  KMeans\KMeans\bin\Release\KMeans.vshost.exe

     文件        490  2013-03-18 17:00  KMeans\KMeans\bin\Release\KMeans.vshost.exe.manifest

     文件       3581  2014-10-08 18:19  KMeans\KMeans\KMeans.csproj

     文件      29141  2014-10-11 09:41  KMeans\KMeans\MainFrm.cs

     文件      16752  2014-10-11 09:41  KMeans\KMeans\MainFrm.Designer.cs

     文件       5817  2014-10-11 09:41  KMeans\KMeans\MainFrm.resx

     文件       1231  2015-01-04 18:03  KMeans\KMeans\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6049  2014-10-09 13:25  KMeans\KMeans\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        636  2015-01-04 18:04  KMeans\KMeans\obj\Debug\KMeans.csproj.FileListAbsolute.txt

     文件        849  2014-10-11 09:41  KMeans\KMeans\obj\Debug\KMeans.csproj.GenerateResource.Cache

     文件       1341  2014-10-11 09:32  KMeans\KMeans\obj\Debug\KMeans.csprojResolveAssemblyReference.cache

     文件      22528  2014-10-11 09:41  KMeans\KMeans\obj\Debug\KMeans.exe

     文件        180  2014-10-11 09:41  KMeans\KMeans\obj\Debug\KMeans.MainFrm.resources

     文件      48640  2014-10-11 09:41  KMeans\KMeans\obj\Debug\KMeans.pdb

     文件        180  2014-10-11 09:28  KMeans\KMeans\obj\Debug\KMeans.Properties.Resources.resources

     文件       6053  2014-10-09 13:26  KMeans\KMeans\obj\Release\DesignTimeResolveAssemblyReferencesInput.cache

     文件        652  2014-10-15 07:10  KMeans\KMeans\obj\Release\KMeans.csproj.FileListAbsolute.txt

     文件        849  2014-10-15 07:10  KMeans\KMeans\obj\Release\KMeans.csproj.GenerateResource.Cache

     文件       1341  2014-10-09 13:26  KMeans\KMeans\obj\Release\KMeans.csprojResolveAssemblyReference.cache

     文件      21504  2014-10-15 07:10  KMeans\KMeans\obj\Release\KMeans.exe

     文件        180  2014-10-15 07:10  KMeans\KMeans\obj\Release\KMeans.MainFrm.resources

     文件      46592  2014-10-15 07:10  KMeans\KMeans\obj\Release\KMeans.pdb

     文件        180  2014-10-09 13:26  KMeans\KMeans\obj\Release\KMeans.Properties.Resources.resources

     文件       1366  2014-10-09 19:30  KMeans\KMeans\Point.cs

............此处省略22个文件信息

评论

共有 条评论