Separating Axis Theorem For Rotatable Rectangles

#include <climits>

// This assumes that a class or struct called Point is, with x and y member variables
// For example, something like:
//
//   class Point {
//   	public:
//	int x;
//	int y;
//	Point();
//	Point(int xx, int yy);
//    };
//
//

// Helper function to project one vector (point) onto another
float proj(Point p1, Point p2) { return p1.x*p2.x + p1.y*p2.y; }

// Separating axis theorem for collision detection. AKA: Do the two rectangles intersect at any point?
// Here, the rectangles are represented by an array of four points
bool SAT(Point PolyA[4], Point PolyB[4]) {
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			if (i != j) {
				// Check projections onto all normals of the first rectangle...
				float minOne = FLT_MAX; float minTwo = FLT_MAX;
				float maxOne = FLT_MIN; float maxTwo = FLT_MIN;
				Point normal_vec = Point(-(PolyA[i].x - PolyA[j].x), 
									(PolyA[i].y - PolyA[j].y));
				for (int k = 0; k < 4; k++) {
					float check = proj(PolyA[k], normal_vec);
					if (check > maxOne) { maxOne = check; }
					if (check < minOne) { minOne = check; }
					check = proj(PolyB[k], normal_vec);
					if (check > maxTwo) { maxTwo = check; }
					if (check < minTwo) { minTwo = check; }
				}

				// ... And if there is no intersection, then we're done.
				if (minOne > maxTwo || maxOne < minTwo) { return false; }

				// Check projections onto all normals of the second rectangle...
				minOne = minTwo = FLT_MAX;
				maxOne = maxTwo = FLT_MIN;
				normal_vec = Point(-(PolyB[i].x - PolyB[j].x), (PolyB[i].y - PolyB[j].y));
				for (int k = 0; k < 4; k++) {
					float check = proj(PolyA[k], normal_vec);
					if (check > maxOne) { maxOne = check; }
					if (check < minOne) { minOne = check; }
					check = proj(PolyB[k], normal_vec);
					if (check > maxTwo) { maxTwo = check; }
					if (check < minTwo) { minTwo = check; }
				}
				// ... And if there is no intersection, then we're done.
				if (minOne > maxTwo || maxOne < minTwo) { return false; }
			}
		}
	}
	// If we haven't returned false yet, then the rectangles overlap.
	return true;
}