code: public void getClosestPoint(Vector2f point, Vector2f result) {
  		loc.set(point);
  		loc.sub(start);
  
  		float projDistance = vec.dot(loc);
  
  		projDistance /= vec.lengthSquared();
  
  		if (projDistance < 0) {
  			result.set(start);
  			return;
  		}
  		if (projDistance > 1) {
  			result.set(end);
  			return;
  		}
  
  		result.x = start.getX() + projDistance * vec.getX();
  		result.y = start.getY() + projDistance * vec.getY();
  	}
docs: Get the closest point on the line to a given point
  
  @param point
  The point which we want to project
  @param result
  The point on the line closest to the given point