/// <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; }
标签:Vector3,center,point,float,切点,Unity,计算,dis From: https://www.cnblogs.com/Jason-c/p/17826196.html