• 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();
        }
    
  • 相关阅读:
    Linux系统负载
    full nat
    close wait 状态的随想
    记录一下 性能分析问题
    golang 反射
    socket里面那个又爱又恨的锁
    Difference between skbuff frags and frag_list
    浅析TCP协议---转载
    http 怎样关闭
    http 响应 ngx_http_send_header ngx_http_output_filter
  • 原文地址:https://www.cnblogs.com/SnowPrince/p/14436848.html
Copyright © 2020-2023  润新知