Unity 计算圆的切点
/// <summary> /// 计算过圆外一点的切点,在圆上的切点 /// </summary> /// <param name="center"></param> /// <param name="radius"></param> /// <param name="point"></param> /// <param name="tanPoint1"></param> /// <param name="tanPoint2"></param> /// <returns></returns> public static bool GetTangentPoint(Vector3 center, float radius, Vector3 point, out Vector3 tanPoint1, out Vector3 tanPoint2) { float dis = Vector3.Distance(center, point); if (dis <= 0 || radius < 0 || dis < radius) { //点必须在圆的外部 tanPoint1 = point; tanPoint2 = point; return false; } float acos = Mathf.Acos(radius / dis) * Mathf.Rad2Deg;//根据余弦求出角度 Vector3 dir = point - center; //绕着Y轴旋转向量,模长是半径,得到的点就是切点 tanPoint1 = (Quaternion.Euler(0, acos, 0) * dir).normalized * radius + center; tanPoint2 = (Quaternion.Euler(0, -acos, 0) * dir).normalized * radius + center; return true; }
博客园Jason_c微信打赏码
如果本篇文档对你有帮助,打赏Jason_c根华子吧,他的私房钱被老婆没收了,呜呜!