zoukankan      html  css  js  c++  java
  • 两点计算角度

    http://www.cnblogs.com/aoldman/archive/2013/07/04/3171559.html

    /// <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));
          }
  • 相关阅读:
    Django连接SQL Server,安装相关扩展包及相关配置
    安装pipenv
    报错及网络上的解决方案
    Nucleus-SE迁移:未实现的设施和兼容性
    RTOS诊断和错误检查
    Nucleus SE RTOS初始化和启动
    Nucleus 实时操作系统中断(下)
    Nucleus 实时操作系统中断(上)
    系统时间
    应用程序计时器
  • 原文地址:https://www.cnblogs.com/donaldlee2008/p/5855215.html
Copyright © 2011-2022 走看看