/// <summary>
        /// Return the closest point on the surface of the capsule
        ///
        /// </summary>
        public Vector3 GetClosestPoint(Vector3 k)
        {
            float dist = Vector3.Dot(k - _p1, _delta);

            //k projection is outside the [_p1, _p2] interval, closest to _p1
            if (dist <= 0.0f)
            {
                return(_topSphere.GetClosestPoint(k));
            }
            //k projection is outside the [_p1, p2] interval, closest to _p2
            else if (dist >= _deltaSquared)
            {
                Vector3 closestPoint    = Vector3.zero;
                bool    canApplyGravity = _bottomCircle.GetClosestPointOnDisc(k, ref closestPoint);
                if (!canApplyGravity)
                {
                    throw new Exception("can't be possible, see AllowBottom for more information");
                }
                return(closestPoint);
            }
            //k projection is inside the [_p1, p2] interval
            else
            {
                dist = dist / _deltaSquared;
                Vector3 pointOnLine        = _p1 + dist * _delta;
                Vector3 pointOnSurfaceLine = pointOnLine + ((k - pointOnLine).FastNormalized() * _realRadius);
                return(pointOnSurfaceLine);
            }
        }
        /// <summary>
        /// Return the closest point on the surface of the cone
        ///
        /// </summary>
        public Vector3 GetClosestPoint(Vector3 k)
        {
            float dist = Vector3.Dot(k - _p1, _delta);

            //k projection is outside the [_p1, _p2] interval, closest to _p1
            if (dist <= 0.0f)
            {
                return(_p1);
            }
            //k projection is outside the [_p1, p2] interval, closest to _p2
            else if (dist >= _deltaDistSquared)
            {
                Vector3 closestPoint    = Vector3.zero;
                bool    canApplyGravity = _circleBase.GetClosestPointOnDisc(k, ref closestPoint);
                if (!canApplyGravity)
                {
                    throw new Exception("can't be possible, see AllowBottom for more information");
                }
                return(closestPoint);
            }
            //k projection is inside the [_p1, p2] interval
            else
            {
                dist = dist / _deltaDistSquared;
                Vector3 pointOnLine  = _p1 + dist * _delta;
                Vector3 closestPoint = ThalesCalculation(k, pointOnLine);
                return(closestPoint);
            }
        }
Exemple #3
0
        public Vector3 GetClosestPoint(Vector3 k)
        {
            if (_circle.IsAbove(k))
            {
                return(Position + ((k - Position).FastNormalized() * _realRadius));
            }
            Vector3 closestPoint = Vector3.zero;

            _circle.GetClosestPointOnDisc(k, ref closestPoint);
            return(closestPoint);
        }
Exemple #4
0
 /// <summary>
 /// Return the closest point on the surface of the cylinder
 /// https://diego.assencio.com/?index=ec3d5dfdfc0b6a0d147a656f0af332bd
 ///
 /// </summary>
 public bool GetClosestPoint(Vector3 k, ref Vector3 closestPoint)
 {
     return(_circle.GetClosestPointOnDisc(k, ref closestPoint));
 }