首页 > 代码库 > 计算两点之间的角度的代码

计算两点之间的角度的代码

+ View Code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/// 离心率   /// 返回两点间的角度
  private double PointToAngle(Point AOrigin, Point APoint, double AEccentricity)
  {
  if (APoint.X == AOrigin.X)
if (APoint.Y > AOrigin.Y)
  return Math.PI * 0.5;
  else return Math.PI * 1.5;
  else if (APoint.Y == AOrigin.Y)
  if (APoint.X > AOrigin.X)
  return 0;
  else return Math.PI;
  else
  {
  double Result = Math.Atan((AOrigin.Y - APoint.Y) /
  (AOrigin.X - APoint.X) * AEccentricity);
  if ((APoint.X <</SPAN> AOrigin.X) && (APoint.Y > AOrigin.Y))
  return Result + Math.PI;
  else if ((APoint.X <</SPAN> AOrigin.X) && (APoint.Y <</SPAN> AOrigin.Y))
  return Result + Math.PI;
  else if ((APoint.X > AOrigin.X) && (APoint.Y <</SPAN> AOrigin.Y))
  return Result + 2 * Math.PI;
  else return Result;
  }
  
  }