博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
两点计算角度
阅读量:6694 次
发布时间:2019-06-25

本文共 1747 字,大约阅读时间需要 5 分钟。

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));
      
}

转载于:https://www.cnblogs.com/donaldlee2008/p/5855215.html

你可能感兴趣的文章
如何避开采购黑幕 高效透明地进行招投标管理?
查看>>
[20180628]expdp与rows=n.txt
查看>>
鱼鹰软件签约医学传播企业麦迪卫康
查看>>
解决ESXI不支持USB移动硬盘
查看>>
js中的事件委托详解
查看>>
区块链智能合约是什么?
查看>>
redis持久化快速回忆手册
查看>>
周庆钢:大数据驱动企业管理与营销决策
查看>>
js读取cookie信息
查看>>
Android第三方开源FloatingActionButton(com.getbase.floatingactionbutton): FloatingActionsMenu【3】...
查看>>
Python3—— collections模块
查看>>
WebLogic口令猜解工具【Python脚本】
查看>>
消灭天价药,AI会成为新药神吗?
查看>>
[增删改查] 使用 React 做后台管理 CRUD 界面和 RESTful 交互
查看>>
springboot demo
查看>>
PostgreSQL 11 preview - 多阶段并行聚合array_agg, string_agg
查看>>
Linux下查看某个命令的参数
查看>>
CUBA Platform 7.0.4 发布,企业级应用开发平台
查看>>
KodExplorer 4.40 发布,权限机制优化
查看>>
北京软件造价评估联盟:开启软件成本度量新篇章
查看>>