Ejemplo n.º 1
0
        //Assumes the point is already on the line somewhere
        public static Vector3 ClampToSegment(Vector3 point, Vector3 linePoint1, Vector3 linePoint2)
        {
            Vector3 lineDirection = linePoint2 - linePoint1;

            if (!GeometryUtil.IsInDirection(point - linePoint1, lineDirection))
            {
                point = linePoint1;
            }
            else if (GeometryUtil.IsInDirection(point - linePoint2, lineDirection))
            {
                point = linePoint2;
            }

            return(point);
        }