/// <summary> /// return the closest point on the disc from K, if the GravityInfo permit it /// </summary> /// <param name="k"></param> /// <param name="canApplyGravity"></param> /// <param name="gravityDisc"></param> /// <returns></returns> public bool GetClosestPointOnDiscIfWeCan(Vector3 k, GravityOverrideDisc gravityDisc, out Vector3 closestPoint) { closestPoint = Vector3.zero; if (!gravityDisc.CanApplyGravity || (!AllowBottom && !_plane.IsAbove(k))) { return(false); } //project point to a plane Vector3 kProjected = ExtPlane.ProjectPointInPlane(_plane, k); //if dist² < radius², this projected point is inside the circle float distSquared = (kProjected - _plane.Point).sqrMagnitude; bool isInsideShape = distSquared < _radiusSquared; if (isInsideShape) { if (!gravityDisc.Face) { return(false); } closestPoint = kProjected; return(true); } if (!gravityDisc.Borders) { return(false); } //return the closest point on the circle (extremity of the disc) closestPoint = _plane.Point + (kProjected - _plane.Point).FastNormalized() * _radius; return(true); }
/// <summary> /// Return the closest point on the disc from k /// </summary> public bool GetClosestPointOnDisc(Vector3 k, ref Vector3 closestPoint) { closestPoint = Vector3.zero; if (!AllowBottom && !_plane.IsAbove(k)) { return(false); } //project point to a plane Vector3 kProjected = ExtPlane.ProjectPointInPlane(_plane, k); //if dist² < radius², this projected point is inside the circle float distSquared = (kProjected - _plane.Point).sqrMagnitude; bool isInsideShape = distSquared < _radiusSquared; if (isInsideShape) { closestPoint = kProjected; } else { closestPoint = _plane.Point + (kProjected - _plane.Point).FastNormalized() * _radius; } return(true); }
/// <summary> /// return the closest point on the circle from k /// </summary> /// <param name="k"></param> /// <returns></returns> public Vector3 GetClosestPointOnCircle(Vector3 k) { //project point to a plane Vector3 kProjected = ExtPlane.ProjectPointInPlane(_plane, k); //return the closest point on the circle Vector3 pointExtremity = _plane.Point + (kProjected - _plane.Point).FastNormalized() * _radius; return(pointExtremity); }
/// <summary> /// assume k is NOT on the same plane as the circle, we first do a projection /// √( | xp−xc |² +| yp−yc |²) < r /// </summary> /// <param name="k"></param> /// <returns></returns> public bool IsInsideShapeWithProjection(Vector3 k) { if (!AllowBottom && !_plane.IsAbove(k)) { return(false); } Vector3 kProjected = ExtPlane.ProjectPointInPlane(_plane, k); float distSquared = (kProjected - _plane.Point).sqrMagnitude; return(distSquared < _radiusSquared); }