GetAngleByTwoPointUtility.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using Blue;
  3. using UnityEngine;
  4. public interface IGetAngleByTwoPointUtility:IUtility
  5. {
  6. double GetAngleByTwoPoint(Vector2 startPoint, Vector2 endPoint);
  7. double GetAngleByTwoPoint(float startPoint_X, float startPoint_Y, float endPoint_X, float ednPoint_Y);
  8. }
  9. public class GetAngleByTwoPointUtility : IGetAngleByTwoPointUtility
  10. {
  11. /// <summary>
  12. /// 根据两点求角度
  13. /// </summary>
  14. /// <param name="startPoint">开始点坐标</param>
  15. /// <param name="endPoint">结束点坐标</param>
  16. /// <returns>角度</returns>
  17. double IGetAngleByTwoPointUtility.GetAngleByTwoPoint(Vector2 startPoint,Vector2 endPoint)
  18. {
  19. return GetAngleByTwoPoint(startPoint.x,startPoint.y,endPoint.x,endPoint.y);
  20. }
  21. /// <summary>
  22. /// 根据两点求角度
  23. /// </summary>
  24. /// <param name="startPoint_X">开始点X值</param>
  25. /// <param name="startPoint_Y">开始点Y值</param>
  26. /// <param name="endPoint_X">结束点X值</param>
  27. /// <param name="ednPoint_Y">结束点Y值</param>
  28. /// <returns>角度</returns>
  29. public double GetAngleByTwoPoint(float startPoint_X,float startPoint_Y ,float endPoint_X,float ednPoint_Y)
  30. {
  31. return Math.Atan2(ednPoint_Y - startPoint_Y, endPoint_X - startPoint_X) * (180.0 / Math.PI);
  32. }
  33. }