game-engine/src/main/java/com/jzy/game/engine/math/Intersector.java
/** Returns a point on the segment nearest to the specified point. */
Returns a point on the segment nearest to the specified point.
Returns a point on the segment nearest to the specified point .
public static Vector2 nearestSegmentPoint(Vector2 start, Vector2 end, Vector2 point, Vector2 nearest) {
		float length2 = start.dst2(end);
		if (length2 == 0)
			return nearest.set(start);
		float t = ((point.x - start.x) * (end.x - start.x) + (point.y - start.y) * (end.y - start.y)) / length2;
		if (t < 0)
			return nearest.set(start);
		if (t > 1)
			return nearest.set(end);
		return nearest.set(start.x + t * (end.x - start.x), start.y + t * (end.y - start.y));
	}
public static Vector2 nearestSegmentPoint ( Vector2 start , Vector2 end , Vector2 point , Vector2 nearest ) { float length2 = start . dst2 ( end ) ; if ( length2 == 0 ) return nearest . set ( start ) ; float t = ( ( point . x - start . x ) * ( end . x - start . x ) + ( point . y - start . y ) * ( end . y - start . y ) ) / length2 ; if ( t < 0 ) return nearest . set ( start ) ; if ( t > 1 ) return nearest . set ( end ) ; return nearest . set ( start . x + t * ( end . x - start . x ) , start . y + t * ( end . y - start . y ) ) ; }
Returns a point on the segment nearest to the specified point.
Returns a point on the segment nearest to the specified point .