首页 > 其他分享 >任意三点画圆弧

任意三点画圆弧

时间:2023-12-22 15:25:43浏览次数:26  
标签:三点 pt double System Vector 圆弧 using 任意 Math

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

namespace WindowsFormsApp2
{
  public partial class FormDrawArc : Form
  {
    public FormDrawArc()
    {
      InitializeComponent();
    }

    PointF[] pt = new PointF[3];
    public double Rad2Deg = 180 / Math.PI;
    private void Form6_MouseDown(object sender, MouseEventArgs e)
    {
      Graphics gs = this.CreateGraphics();

      if (pt[0].X == 0 && pt[0].Y == 0)
      {

        pt[0].X = e.X;
        pt[0].Y = e.Y;
      }
      else if (pt[1].X == 0 && pt[1].Y == 0)
      {

        pt[1].X = e.X;
        pt[1].Y = e.Y;
      }
      else if (pt[2].X == 0 && pt[2].Y == 0)
      {

        pt[2].X = e.X;
        pt[2].Y = e.Y;
        PointF a = pt[0];
        PointF b = pt[1];
        PointF c = pt[2];

        double d = 2 * (a.X - c.X) * (c.Y - b.Y) + 2 * (b.X - c.X) * (a.Y - c.Y);
        double m1 = (Math.Pow(a.X, 2) - Math.Pow(c.X, 2) + Math.Pow(a.Y, 2) - Math.Pow(c.Y, 2));
        double m2 = (Math.Pow(c.X, 2) - Math.Pow(b.X, 2) + Math.Pow(c.Y, 2) - Math.Pow(b.Y, 2));
        double nx = m1 * (c.Y - b.Y) + m2 * (c.Y - a.Y);
        double ny = m1 * (b.X - c.X) + m2 * (a.X - c.X);
        double cx = nx / d;
        double cy = ny / d;
        double dx = cx - a.X;
        double dy = cy - a.Y;
        double distance = Math.Sqrt(dx * dx + dy * dy);
        Vector va = new Vector(a.X - cx, a.Y - cy);
        Vector vb = new Vector(b.X - cx, b.Y - cy);
        Vector vc = new Vector(c.X - cx, c.Y - cy);
        Vector xaxis = new Vector(1, 0);
        float startAngle = (float)Vector.AngleBetween(xaxis, va);
        float sweepAngle = (float)(Vector.AngleBetween(va, vb) + Vector.AngleBetween(vb, vc));
        gs.DrawArc(new Pen(Color.Cyan,3),
            (float)(cx - distance), (float)(cy - distance),
            (float)(distance * 2), (float)(distance * 2),
            startAngle, sweepAngle);

        pt = new PointF[3];
      }
    }
  }
}

 

标签:三点,pt,double,System,Vector,圆弧,using,任意,Math
From: https://www.cnblogs.com/echo-efun/p/17921644.html

相关文章

  • 任意整数分频
    //**************************************************************************任意整数分频,占空比为1:2//**************************************************************************modulediv_clk//========================<参数>=......
  • 任意多点按某一方向排序
    List<PointF>SortPoints(PointF[]points){List<PointF>result=newList<PointF>();PointFcenter=GetGravityPoint(points.ToList());PointFx=newPointF(center.X+1,center.Y);PointFOX=newPointF(1,......
  • WPF中通过附加属性实现任意控件拖动调整大小
    publicclassResizeBehavior{//附加属性用于标识控件是否可调整大小publicstaticreadonlyDependencyPropertyIsResizableProperty=DependencyProperty.RegisterAttached("IsResizable",typeof(bool),typeof(ResizeBehavior),newP......
  • 使用汇编和反汇编引擎写一个x86任意地址hook
    最简单的Hook刚开始学的时候,用的hook都是最基础的5字节hook,也不会使用hook框架,hook流程如下:构建一个jmp指令跳转到你的函数(函数需定义为裸函数)保存被hook地址的至少5字节机器码,然后写入构建的jmp指令接着在你的代码里做你想要的操作以内联汇编的形式执行被hook地址5字节机......
  • 下面,我讲三点意见
    领导讲话都喜欢三点意见一个意见三个办法如何提意见对三述对象的意见和建议领导会议总结提三点要求“讲三点”有哪些好处? 首先,迅速组织文字。讲三点很容易就把本来毫无头绪的一段语言,整理成逻辑非常清晰的语言。其次,让你的文字逻辑清晰有力量。可以让别人感觉你是一个......
  • Wpf应用Path路径绘制圆弧
    [原]Wpf应用Path路径绘制圆弧 1. 移动指令:MoveCommand(M):M起始点 或者:m起始点比如:M100,240或m100,240使用大写M时,表示绝对值;使用小写m时;表示相对于前一点的值,如果前一点没有指定,则使用(0,0)。2. 绘制指令(DrawCommand):我们可以绘制以下形状:(1)直线:Line(L)(2)......
  • 苹果微信换图标方法!教你微信快速改任意图标教程(附图标)
    微信作为如今的社交大哥,使用人数早已突破了十亿人次,可见其用户体量之多堪称第一!用户量越多大家的需求也就越多,就像苹果微信想要实现安卓微信的各种功能,因为iOS系统的限制很多都是实现不了的。就比如更换微信图标这件事,安卓只需要更换一个喜欢的系统主题足以,但对于iPhone来说......
  • 任意类型多项式乘法
    目录前言前置知识定义与记号单位根分圆多项式Cantor'sAlgorithm规避单位根递归计算卷积做\(\mathcal{I}_p\)上的DFT时间复杂度规避除法实现细节参考资料参考文献参考代码前言所谓“任意类型”,事实上指的是一种代数结构\(\mathcal{A}=(D,+,\cdot)\),满足:\(+:D\timesD\toD......
  • 画任意正多边形
    移动到初始位置看上次画的线还在所以我们要用全部擦除做个示范看看60度什么样外角  ......
  • 【C++】异常处理 ④ ( 异常接口声明 | 异常接口语法 | 抛出一种类型的异常 | 抛出多种
    文章目录一、异常接口声明1、异常接口引入2、异常接口语法3、抛出一种类型的异常4、抛出多种类型的异常5、抛出任何类型异常-不声明异常接口/声明throw(...)6、不能抛出任何类型异常-声明throw()7、抛出异常类型错误博客总结://1.不会抛出异常voidfun()throw();......