12345678910111213141516171819202122232425262728293031323334353637 |
- using System;
- using Blue;
- using UnityEngine;
- public interface IGetAngleByTwoPointUtility:IUtility
- {
- double GetAngleByTwoPoint(Vector2 startPoint, Vector2 endPoint);
- double GetAngleByTwoPoint(float startPoint_X, float startPoint_Y, float endPoint_X, float ednPoint_Y);
- }
- public class GetAngleByTwoPointUtility : IGetAngleByTwoPointUtility
- {
- /// <summary>
- /// 根据两点求角度
- /// </summary>
- /// <param name="startPoint">开始点坐标</param>
- /// <param name="endPoint">结束点坐标</param>
- /// <returns>角度</returns>
- double IGetAngleByTwoPointUtility.GetAngleByTwoPoint(Vector2 startPoint,Vector2 endPoint)
- {
- return GetAngleByTwoPoint(startPoint.x,startPoint.y,endPoint.x,endPoint.y);
- }
- /// <summary>
- /// 根据两点求角度
- /// </summary>
- /// <param name="startPoint_X">开始点X值</param>
- /// <param name="startPoint_Y">开始点Y值</param>
- /// <param name="endPoint_X">结束点X值</param>
- /// <param name="ednPoint_Y">结束点Y值</param>
- /// <returns>角度</returns>
- public double GetAngleByTwoPoint(float startPoint_X,float startPoint_Y ,float endPoint_X,float ednPoint_Y)
- {
- return Math.Atan2(ednPoint_Y - startPoint_Y, endPoint_X - startPoint_X) * (180.0 / Math.PI);
- }
- }
|