public static Ray getClosestIntersect(Vector origin, Vector direction, PhysicsObject source,
			List<PhysicsObject> objects) {
		direction = direction.norm();

		Vec2 point1 = new Vec2(origin.x, origin.y);
		Vec2 point2 = new Vec2(origin.x + direction.x * 1000, origin.y + direction.y * 1000);

		// Get a iterator for the Walls
		ListIterator<PhysicsObject> objectsI = objects.listIterator();

		// Variable that stores the distance to the closest intersection found
		float closestProximitySquared = Float.MAX_VALUE;
		// Variable containing the position of the closest intersection found
		Vector closestIntersection = null;
		PhysicsObject closestObject = null;

		// Declare variable to store the Shape's number of segments
		int linesCount;
		// Declare variable to store the Shape's number of segments
		Vec2[] vertices;

		// Run through the list of Walls
		while (objectsI.hasNext()) {
			// Load a Wall
			PhysicsObject p = objectsI.next();

			if (p.equals(source))
				continue;

			// WALLS ARE ALWAYS POLYGON SHAPES OR THIS EXPLODES!

			Vec2[] polyVertices = p.getVertices(); 
			
			// Load the vertices of this Shape
			vertices = new Vec2[polyVertices.length];
			// Load the number of lines in this Shape
			linesCount = vertices.length;

			for (int i = 0; i < vertices.length; i++) {
				vertices[i] = (p.getBody().getWorldPoint(polyVertices[i]));
			}

			// This iterator represents the end point of a segment
			int ii = 1;
			// For the number of lines in the Shape
			for (int i = 0; i < linesCount; i++) {
				Vector v1 = new Vector(vertices[i].x, vertices[i].y);
				Vector v2 = new Vector(vertices[ii].x, vertices[ii].y);

				// Call Java2D intersect method which tells us IF there is
				// an
				// intersection between the given lines
				if (linesIntersect(
				// Supply the beginning and end point of the provided
				// segment
						point1.x, point1.y, point2.x, point2.y,

						// The start-vertex of the Shape's segment
						v1.x, v1.y,
						// The end-vertex of the Shape's segment
						v2.x, v2.y)) {

					float x1 = point1.x;
					float x2 = point2.x;
					float x3 = vertices[i].x;
					float x4 = vertices[ii].x;
					float y1 = point1.y;
					float y2 = point2.y;
					float y3 = vertices[i].y;
					float y4 = vertices[ii].y;

					Vector intersection = getLineLineIntersection(x1, y1, x2, y2, x3, y3, x4, y4);

					// Calculate the distance to this intersection
					float proximitySquared = intersection.minus(origin).mag2();
					// If it is closer than the closest yet found
					if (proximitySquared < closestProximitySquared) {
						// Update these variables
						closestProximitySquared = proximitySquared;
						closestIntersection = intersection;
						closestObject = p;
					}
				}

				// Increment Shape's segment end-vertex
				ii++;
				// If it is greater than the array's length, we take the
				// first
				// vertex at index zero
				if (ii == linesCount) {
					ii = 0;
				}

			}

		}

		// Return the closest intersection found or NULL if there were no
		// intersections
		if (closestIntersection != null)
			return new Ray(origin, closestIntersection, source, closestObject);
		else return null;
	}