• 大小: 300KB
    文件类型: .rar
    金币: 2
    下载: 3 次
    发布日期: 2021-06-12
  • 语言: C#
  • 标签: 圆拟合  Circle-Fitti  

资源简介

这是一个圆拟合器,它能产生随机点,也能读取相应格式的点数据。采用最小二乘法,实现对任意给定点的圆拟合。使用语言为C#

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;

namespace Circle_Fitting
{
    public partial class Form1 : Form
    {
        private DPoint[] _Points;   //用来存储产生的随机点坐标
        private DPoint[] _OrignalPoints;
        private int _PointNum;     //产生的随机点的个数
        bool _IsCreatePoint = false;       //随机点是否生成成功    
        bool _IsFitting = false;
        float _centerX _centerY _R;  //这三个均是屏幕坐标

        public Form1()
        {
            InitializeComponent();

            _PointNum = 1000;     //设定有1000个点
            _IsCreatePoint = false;
            _IsFitting = false;
            _Points = new DPoint[_PointNum];
            _OrignalPoints = _Points.Clone() as DPoint[];

            this.openFileDialog1.FileName = “文本文档“;
            this.numericUpDownPointNum.Value = 20;
            this.CenterLabel.Text = _centerX.ToString() + ““ + _centerY.ToString();
            this.RadiusLabel.Text = _R.ToString();
        }

        /// 
        /// 通过随机函数产生随机点
        /// 

        private void CreateRandomPoints()
        {
            Random ro = new Random();
            for (int i = 0; i < _PointNum; i++)
            {
                for (int j = 0; j < 1000; j++)
                {
                    int iMin = 0 iMax = 500;
                    float x = ro.Next(iMin iMax) - 250;
                    float y = ro.Next(iMin iMax) - 250;
                    float dist = (float)Math.Sqrt(x * x + y * y);
                    if (dist > 150 && dist < 220)
                    {
                        _Points[i] = new DPoint(x y);
                    }
                }
            }
            _OrignalPoints = _Points.Clone() as DPoint[];
        }

        /// 
        /// 坐标转换,将实际坐标转成屏幕坐标
        /// 

        private void CoordinatesTransformation()
        {
            for(int i=0;i<_PointNum;i++)
            {
                _Points[i].X += 250;
                _Points[i].Y = -_Points[i].Y + 250;
            }

        }

        /// 
        /// 最小二乘法,得到圆心坐标和半径三个数据
        /// 

        private void LeastSquareFitting()
        {
            if (_PointNum < 3)
                return;

            float x1 = 0.0f;  //x一次方的初值
            float y1 = 0.0f;
            float x2 = 0.0f;  //x平方的初始值
            float y2 = 0.0f;
            float x3 = 0.0f;  //x立方的初始值
            float y3 = 0.0f;
            float x1y1 = 0.0f;
            float x1y2 = 0.0f;
            float x2y1 = 0.0f;

            for (int i = 0; i < _PointNum; i++)
            {
                x1 = x1 + _Points[i].X;
                y1 = y1 + _Points[i].Y;
                x2 = x2 + _Points[i].X * _Points[i].X;
                y2 = y2 + _Points[i]

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

     文件     153088  2010-12-11 22:28  Circle-Fitting\Circle Fitting\Circle Fitting\bin\Debug\Circle Fitting.exe

     文件      34304  2010-12-11 22:28  Circle-Fitting\Circle Fitting\Circle Fitting\bin\Debug\Circle Fitting.pdb

     文件      14328  2010-12-15 19:10  Circle-Fitting\Circle Fitting\Circle Fitting\bin\Debug\Circle Fitting.vshost.exe

     文件        490  2007-07-21 01:33  Circle-Fitting\Circle Fitting\Circle Fitting\bin\Debug\Circle Fitting.vshost.exe.manifest

     文件      67646  2010-07-05 21:12  Circle-Fitting\Circle Fitting\Circle Fitting\bin\Debug\designFloat copy.ico

     文件        856  2010-12-11 21:17  Circle-Fitting\Circle Fitting\Circle Fitting\bin\Debug\Help.txt

     文件        189  2010-12-11 16:14  Circle-Fitting\Circle Fitting\Circle Fitting\bin\Debug\示例数据.txt

     文件     152576  2010-12-11 21:37  Circle-Fitting\Circle Fitting\Circle Fitting\bin\Release\Circle Fitting.exe

     文件      32256  2010-12-11 21:37  Circle-Fitting\Circle Fitting\Circle Fitting\bin\Release\Circle Fitting.pdb

     文件      14328  2010-12-11 21:38  Circle-Fitting\Circle Fitting\Circle Fitting\bin\Release\Circle Fitting.vshost.exe

     文件        490  2007-07-21 01:33  Circle-Fitting\Circle Fitting\Circle Fitting\bin\Release\Circle Fitting.vshost.exe.manifest

     文件       3951  2010-12-11 21:44  Circle-Fitting\Circle Fitting\Circle Fitting\Circle Fitting.csproj

     文件      67646  2010-12-11 21:36  Circle-Fitting\Circle Fitting\Circle Fitting\designFloat copy.ico

     文件      10069  2010-12-11 22:28  Circle-Fitting\Circle Fitting\Circle Fitting\Form1.cs

     文件      13136  2010-12-11 22:28  Circle-Fitting\Circle Fitting\Circle Fitting\Form1.Designer.cs

     文件     108192  2010-12-11 22:28  Circle-Fitting\Circle Fitting\Circle Fitting\Form1.resx

     文件       1055  2010-12-15 19:10  Circle-Fitting\Circle Fitting\Circle Fitting\obj\Debug\Circle Fitting.csproj.FileListAbsolute.txt

     文件        847  2010-12-11 22:28  Circle-Fitting\Circle Fitting\Circle Fitting\obj\Debug\Circle Fitting.csproj.GenerateResource.Cache

     文件     153088  2010-12-11 22:28  Circle-Fitting\Circle Fitting\Circle Fitting\obj\Debug\Circle Fitting.exe

     文件      34304  2010-12-11 22:28  Circle-Fitting\Circle Fitting\Circle Fitting\obj\Debug\Circle Fitting.pdb

     文件      68212  2010-12-11 22:28  Circle-Fitting\Circle Fitting\Circle Fitting\obj\Debug\Circle_Fitting.Form1.resources

     文件        180  2010-12-11 21:44  Circle-Fitting\Circle Fitting\Circle Fitting\obj\Debug\Circle_Fitting.Properties.Resources.resources

     文件        621  2010-12-11 21:38  Circle-Fitting\Circle Fitting\Circle Fitting\obj\Release\Circle Fitting.csproj.FileListAbsolute.txt

     文件        847  2010-12-11 21:37  Circle-Fitting\Circle Fitting\Circle Fitting\obj\Release\Circle Fitting.csproj.GenerateResource.Cache

     文件     152576  2010-12-11 21:37  Circle-Fitting\Circle Fitting\Circle Fitting\obj\Release\Circle Fitting.exe

     文件      32256  2010-12-11 21:37  Circle-Fitting\Circle Fitting\Circle Fitting\obj\Release\Circle Fitting.pdb

     文件      68212  2010-12-11 21:37  Circle-Fitting\Circle Fitting\Circle Fitting\obj\Release\Circle_Fitting.Form1.resources

     文件        180  2010-12-11 21:36  Circle-Fitting\Circle Fitting\Circle Fitting\obj\Release\Circle_Fitting.Properties.Resources.resources

     文件        495  2010-12-11 21:44  Circle-Fitting\Circle Fitting\Circle Fitting\Program.cs

     文件       1366  2010-12-07 19:42  Circle-Fitting\Circle Fitting\Circle Fitting\Properties\AssemblyInfo.cs

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

评论

共有 条评论