• C# 两条线获取角度,角度原点距离获取另一点


    C# 两条线获取角度,角度原点距离获取另一点

        // 获得鼠标点击位置和原点组成的线与原点垂线的角度
        private double GetAngel()
        {
            int X = Convert.ToInt32(numericUpDown1.Value);
            int Y = Convert.ToInt32(numericUpDown2.Value);
            Point pictureBox1Point = pictureBox1.PointToClient(Control.MousePosition);
            Point a1 = new Point(X, Y);
            Point a2 = new Point(X, 300);
            Point b1 = new Point(X, Y);
            Point b2 = new Point(pictureBox1Point.X, pictureBox1Point.Y);
            var a = Math.Atan2(a2.Y - a1.Y, a2.X - a1.X);
            var b = Math.Atan2(b2.Y - b1.Y, b2.X - b1.X);
            double angle = 180 * (b - a) / Math.PI;
            return (angle > 0 ? angle : angle + 360);
        }
        /// <summary>
        /// 通过三角函数求终点坐标
        /// </summary>
        /// <param name="angle">角度</param>
        /// <param name="startPoint">起点</param>
        /// <param name="distance">距离</param>
        /// <returns>终点坐标</returns>
        private static double[] getEndPointByTrigonometric(double angle, double[] startPoint, double distance)
        {
            double[] endPoint = new double[2];
            //角度转弧度
            double radian = (angle * Math.PI) / 180;
            //计算新坐标 r 就是两者的距离
            endPoint[0] = startPoint[0] + distance * Math.Cos(radian);
            endPoint[1] = startPoint[1] + distance * Math.Sin(radian);
            return endPoint;
        }
        // 根据角度和原点垂线画线的方法
        private void SettingOutByAngel(Graphics g, float angel)
        {
            float X = Convert.ToInt32(numericUpDown1.Value);
            float Y = Convert.ToInt32(numericUpDown2.Value);
            g.TranslateTransform(X, Y);
            g.RotateTransform(angel + 90);
            g.DrawLine(new Pen(Color.Red), 0, 0, 300, 0);
            g.ResetTransform();
        }
    
  • 相关阅读:
    git命令无法自动补全(sles11.3)
    linux下安装svn出现configure: error: We require OpenSSL; try --with-openssl
    Linux系统下升级Python版本步骤(suse系统)
    git commit --amend
    关于device tree中的interrupts选项
    BufferedInputStream
    FileInputStream
    FileOutputStream
    泛型上下限
    泛型接口
  • 原文地址:https://www.cnblogs.com/SnowPrince/p/14436848.html
Copyright © 2020-2023  润新知