• 两点计算角度


    /// <summary>
          /// 两点计算角度
          /// </summary>
          /// <param name="startx"></param>
          /// <param name="starty"></param>
          /// <param name="endx"></param>
          /// <param name="endy"></param>
          /// <returns></returns>
          public static double CalulateXYAnagle(double startx, double starty, double endx, double endy)
          {

                                  //除数不能为0
              double tan = Math.Atan(Math.Abs((endy - starty) / (endx - startx))) * 180 / Math.PI;
              if (endx > startx && endy > starty)//第一象限
              {
                  return -tan;
              }
              else if (endx > startx && endy < starty)//第二象限
              {
                  return tan;
              }
              else if (endx < startx && endy > starty)//第三象限
              {
                  return tan - 180;
              }
              else
              {
                  return 180 - tan;
              }

          }

      /// <summary>
            ///     计算旋转角度
            /// </summary>
            /// <param name="nowpoint"></param>
            /// <returns></returns>
            public double ComputeAngle(Point nowpoint)
            {
                //斜边长度
                double length = PointLegth(nowpoint, CentPoint);
                //对边比斜边 sin
                double hudu = Math.Asin(Math.Abs(nowpoint.Y - CentPoint.Y)/length);
                double ag = hudu*180/Math.PI;
                //第一象限90-
                if ((CentPoint.X - nowpoint.X) <= 0 && (CentPoint.Y - nowpoint.Y) >= 0)
                    ag = 90 - ag;
                    //第二象限90+
                else if ((CentPoint.X - nowpoint.X) <= 0 && (CentPoint.Y - nowpoint.Y) <= 0)
                    ag = ag + 90;
                    //第三象限270-
                else if ((CentPoint.X - nowpoint.X) >= 0 && (CentPoint.Y - nowpoint.Y) <= 0)
                    ag = 270 - ag;
                    //第四象限270+
                else if ((CentPoint.X - nowpoint.X) >= 0 && (CentPoint.Y - nowpoint.Y) >= 0)
                    ag = ag + 270;
                //偏移
                ag -= 235;
                return ag;
            }
    
            /// <summary>
            ///     计算两点间距离
            /// </summary>
            /// <param name="pa"></param>
            /// <param name="pb"></param>
            /// <returns></returns>
            public double PointLegth(Point pa, Point pb)
            {
                return Math.Sqrt(Math.Pow((pa.X - pb.X), 2) + Math.Pow((pa.Y - pb.Y), 2));
            }
    
  • 相关阅读:
    JavaScript框架设计 一、种子模块
    一、微服务架构概述(spring cloud与docker学习)
    C++之socket编程
    原定于6日的维护延期
    网站将于8月5日或6日进行维护
    JAVA日报
    JAVA日报
    JAVA日报
    JAVA日报
    JAVA日报
  • 原文地址:https://www.cnblogs.com/aoldman/p/3171559.html
Copyright © 2020-2023  润新知