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();
        }
    
  • 相关阅读:
    Windows2008R2安装DNS和SQLServer200r2服务 (9.18第七天)
    Windows2008R2安装iis和iis下搭建web服务器(9.18 第七天)
    Ubuntu 安装phpmyadmin (9.17第六天)
    Ubuntu Navicat链接mysql (9.17第六天)
    Spring之AOP由浅入深
    oracle并行模式(Parallel)
    转:Java后端面试自我学习
    Spring Security 简介
    spring boot入门
    git--分布式版本管理系统
  • 原文地址:https://www.cnblogs.com/SnowPrince/p/14436848.html
Copyright © 2011-2022 走看看