zoukankan      html  css  js  c++  java
  • 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();
        }
    
  • 相关阅读:
    Two strings CodeForces
    Dasha and Photos CodeForces
    Largest Beautiful Number CodeForces
    Timetable CodeForces
    Financiers Game CodeForces
    AC日记——整理药名 openjudge 1.7 15
    AC日记——大小写字母互换 openjudge 1.7 14
    AC日记——将字符串中的小写字母换成大写字母 openjudge 1.7 13
    AC日记——加密的病历单 openjudge 1.7 12
    AC日记——潜伏着 openjudge 1.7 11
  • 原文地址:https://www.cnblogs.com/SnowPrince/p/14436848.html
Copyright © 2011-2022 走看看