/// <summary> /// Checks to see whether a given point is within a specified distance from a circle outline. In the XZ-plane. Outputs the closest t-value (to the given point) on the curve. /// </summary> /// <param name="curve"></param> /// <param name="distanceThreshold"></param> /// <param name="pointOfInterest"></param> /// <param name="t"></param> /// <returns></returns> public static bool IsCloseToCircle3XZ(Circle3XZ circle, float distanceThreshold, Vector3 pointOfInterest, out float t) { Vector3 _circleCenter = circle.center; float _circleRadius = circle.radius; //constrain to XZ plane _circleCenter.y = 0f; pointOfInterest.y = 0f; //initialize output t t = 0.5f; if (distanceThreshold == 0f) { return(pointOfInterest == _circleCenter ? true : false); } else if (distanceThreshold < 0f) { distanceThreshold = Mathf.Abs(distanceThreshold); } float _lesserRadiusSqr = Mathf.Pow(_circleRadius - distanceThreshold, 2f); float _greaterRadiusSqr = Mathf.Pow(_circleRadius + distanceThreshold, 2f); //float _distanceSqr = (pointOfInterest - _circleCenter).sqrMagnitude; float _distanceSqr = circle.DistanceSqr(pointOfInterest, out t); if (_distanceSqr >= _lesserRadiusSqr && _distanceSqr <= _greaterRadiusSqr) { return(true); } else { return(false); } }
/// <summary> /// Checks to see whether a given point is close to a circle outline. In the XZ-plane. /// </summary> /// <param name="circleCenter"></param> /// <param name="radius"></param> /// <param name="pointOfInterest"></param> /// <param name="distance"></param> /// <returns></returns> public static bool IsNearCircleOutlineXZ(Circle3XZ circle, Vector3 pointOfInterest, float distance) { Vector3 _circleCenter = circle.center; float _circleRadius = circle.radius; if (distance == 0f) { return(pointOfInterest == _circleCenter ? true : false); } else if (distance < 0f) { distance = Mathf.Abs(distance); } //constrain to XZ plane _circleCenter.y = 0f; pointOfInterest.y = 0f; float _lesserRadiusSqr = Mathf.Pow(_circleRadius - distance, 2f); float _greaterRadiusSqr = Mathf.Pow(_circleRadius + distance, 2f); float _distanceSqr = (pointOfInterest - _circleCenter).sqrMagnitude; if (_distanceSqr >= _lesserRadiusSqr && _distanceSqr <= _greaterRadiusSqr) { return(true); } else { return(false); } }