• 大小: 55KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-25
  • 语言: C#
  • 标签: C#  

资源简介

采用C#开发经过三个点绘制圆弧的测试程序, 在主界面上用鼠标左键在不同位置按下三次,将绘制经过这三个点的圆弧

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ArcPointTest
{
    public partial class ArcPointTest : Form
    {

        Point FirstPoint = new Point();
        Point SecondPoint = new Point();
        Point ThirdPoint = new Point();

        int PointNum;


        public ArcPointTest()
        {
            InitializeComponent();
            PointNum = 0;
        }



        private void MainForm_MouseClick(object sender MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                Graphics g = this.CreateGraphics();
                SolidBrush m_Brush = new SolidBrush(Color.Blue);

                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

                if (PointNum == 0)
                {
                    FirstPoint.X = e.X;
                    FirstPoint.Y = e.Y;
                }

                if (PointNum == 1)
                {
                    SecondPoint.X = e.X;
                    SecondPoint.Y = e.Y;
                }

                if (PointNum == 2)
                {
                    ThirdPoint.X = e.X;
                    ThirdPoint.Y = e.Y;
                }

                g.FillEllipse(m_Brush e.X - 3 e.Y - 3 6 6);

                PointNum++;
                if (PointNum == 3)
                {
                    PointNum = 0;

                    DrawArcFromThreePoint(g FirstPoint.X FirstPoint.Y SecondPoint.X SecondPoint.Y ThirdPoint.X ThirdPoint.Y);
                }

            }

        }

        /*
         * 利用三点坐标获得圆弧
         */ 

        void DrawArcFromThreePoint(Graphics mImgGraph int x1 int y1 int x2 int y2 int x3 int y3)
        {
            double a = x1 - x2;
            double b = y1 - y2;
            double c = x1 - x3;
            double d = y1 - y3;
            double e = ((x1 * x1 - x2 * x2) + (y1 * y1 - y2 * y2)) / 2.0;
            double f = ((x1 * x1 - x3 * x3) + (y1 * y1 - y3 * y3)) / 2.0;

            double det = b * c - a * d;
            if (Math.Abs(det) > 0.001)
            {
                //x0y0为计算得到的原点
                double x0 = -(d * e - b * f) / det;
                double y0 = -(a * f - c * e) / det;

                SolidBrush OriginBrush = new SolidBrush(Color.Blue);
                mImgGraph.FillEllipse(OriginBrush (int)(x0 - 3) (int)(y0 - 3) 6 6);

                double radius = Math.Sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));

                double angle1;
                double angle2;
                double angle3;

                double sinValue1;
                double cosValue1;
                double sinValue2;
                double cosValue2;
             

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-03-15 08:01  ArcPointTest\
     目录           0  2018-03-15 08:01  ArcPointTest\ArcPointTest\
     文件         187  2018-03-15 08:01  ArcPointTest\ArcPointTest\App.config
     文件        3818  2018-03-15 08:11  ArcPointTest\ArcPointTest\ArcPointTest.csproj
     文件        2185  2018-03-15 08:35  ArcPointTest\ArcPointTest\MainForm.Designer.cs
     文件        6100  2018-03-15 08:35  ArcPointTest\ArcPointTest\MainForm.cs
     文件        5817  2018-03-15 08:35  ArcPointTest\ArcPointTest\MainForm.resx
     文件         542  2018-03-15 08:01  ArcPointTest\ArcPointTest\Program.cs
     目录           0  2018-03-15 08:01  ArcPointTest\ArcPointTest\Properties\
     文件        1454  2018-03-15 08:01  ArcPointTest\ArcPointTest\Properties\AssemblyInfo.cs
     文件        2854  2018-03-15 08:01  ArcPointTest\ArcPointTest\Properties\Resources.Designer.cs
     文件        5612  2018-03-15 08:01  ArcPointTest\ArcPointTest\Properties\Resources.resx
     文件        1099  2018-03-15 08:01  ArcPointTest\ArcPointTest\Properties\Settings.Designer.cs
     文件         249  2018-03-15 08:01  ArcPointTest\ArcPointTest\Properties\Settings.settings
     目录           0  2018-03-15 08:01  ArcPointTest\ArcPointTest\bin\
     目录           0  2018-03-15 08:22  ArcPointTest\ArcPointTest\bin\Debug\
     文件       10752  2018-03-15 08:35  ArcPointTest\ArcPointTest\bin\Debug\ArcPointTest.exe
     文件         187  2018-03-15 08:01  ArcPointTest\ArcPointTest\bin\Debug\ArcPointTest.exe.config
     文件       26112  2018-03-15 08:35  ArcPointTest\ArcPointTest\bin\Debug\ArcPointTest.pdb
     文件       22984  2018-03-15 08:25  ArcPointTest\ArcPointTest\bin\Debug\ArcPointTest.vshost.exe
     文件         187  2018-03-15 08:01  ArcPointTest\ArcPointTest\bin\Debug\ArcPointTest.vshost.exe.config
     目录           0  2018-03-15 08:36  ArcPointTest\ArcPointTest\bin\Release\
     目录           0  2018-03-15 08:01  ArcPointTest\ArcPointTest\obj\
     目录           0  2018-03-15 08:35  ArcPointTest\ArcPointTest\obj\Debug\
     文件         180  2018-03-15 08:35  ArcPointTest\ArcPointTest\obj\Debug\ArcPointTest.ArcPointTest.resources
     文件         180  2018-03-15 08:11  ArcPointTest\ArcPointTest\obj\Debug\ArcPointTest.Properties.Resources.resources
     文件         742  2018-03-15 08:25  ArcPointTest\ArcPointTest\obj\Debug\ArcPointTest.csproj.FileListAbsolute.txt
     文件        1036  2018-03-15 08:35  ArcPointTest\ArcPointTest\obj\Debug\ArcPointTest.csproj.GenerateResource.Cache
     文件        2209  2018-03-15 08:01  ArcPointTest\ArcPointTest\obj\Debug\ArcPointTest.csprojResolveAssemblyReference.cache
     文件       10752  2018-03-15 08:35  ArcPointTest\ArcPointTest\obj\Debug\ArcPointTest.exe
     文件       26112  2018-03-15 08:35  ArcPointTest\ArcPointTest\obj\Debug\ArcPointTest.pdb
............此处省略8个文件信息

评论

共有 条评论