   Separating Axis Theorem (Basic 2D Rectangles)
  I'm trying to implement this in Java for basic 2D rectangles but my collision check keeps resolving to true.  I'd appreciate if someone could either look through my code or even just post the code for a basic implementation of this in any language.  Also, I'm following the article on this site so reffering me to it won't be of any help.import java.lang.Math;public class RectangleCollison {public static double dotProduct(Point p1, Point p2) {return (p1.getX() * p2.getX() + p1.getY() * p2.getY());}public static boolean checkCollision(Rectangle rect1, Rectangle rect2) {Rectangle[] rect = new Rectangle[2];rect[0] = rect1;rect[1] = rect2;Point[] axis = new Point[4];Point[][][] projection = new Point[2][4][4]; //[rectangle][axis][rectangle corner]double[][] scalar = new double[2][4];//[rectangle][projection]double[] max = new double[2];//[rectangle]double[] min = new double[2];//[rectangle]double temp = 0;axis[0] = new Point(rect[0].getUpperRight().getX() - rect[0].getUpperLeft().getX(), rect[0].getUpperRight().getY() - rect[0].getUpperLeft().getY());axis[1] = new Point(rect[0].getUpperRight().getX() - rect[0].getLowerRight().getX(), rect[0].getUpperRight().getY() - rect[0].getLowerRight().getY());axis[2] = new Point(rect[1].getUpperLeft().getX() - rect[1].getLowerLeft().getX(), rect[1].getUpperLeft().getY() - rect[1].getLowerLeft().getY());axis[3] = new Point(rect[1].getUpperLeft().getX() - rect[1].getUpperRight().getX(), rect[1].getUpperLeft().getY() - rect[1].getUpperRight().getY());for (int i = 0; i < 4; i++) {for (int r = 0; r < 2; r++) {temp = (rect[r].getUpperLeft().getX() * axis.getX() + rect[r].getUpperLeft().getY() * axis.getY()) / (Math.pow(axis.getX(), 2) + Math.pow(axis.getY(), 2));projection[r][0] = new Point(temp * axis.getX(), temp * axis.getY());scalar[r][0] = dotProduct(projection[r][0], axis);temp = (rect[r].getUpperRight().getX() * axis.getX() + rect[r].getUpperRight().getY() * axis.getY()) / (Math.pow(axis.getX(), 2) + Math.pow(axis.getY(), 2));projection[r][1] = new Point(temp * axis.getX(), temp * axis.getY());scalar[r][1] = dotProduct(projection[r][1], axis);temp = (rect[r].getLowerRight().getX() * axis.getX() + rect[r].getLowerRight().getY() * axis.getY()) / (Math.pow(axis.getX(), 2) + Math.pow(axis.getY(), 2));projection[r][2] = new Point(temp * axis.getX(), temp * axis.getY());scalar[r][2] = dotProduct(projection[r][2], axis);temp = (rect[r].getLowerLeft().getX() * axis.getX() + rect[r].getLowerLeft().getY() * axis.getY()) / (Math.pow(axis.getX(), 2) + Math.pow(axis.getY(), 2));projection[r][3] = new Point(temp * axis.getX(), temp * axis.getY());scalar[r][3] = dotProduct(projection[r][3], axis);}min[0] = scalar[0][0];max[0] = scalar[0][0];min[1] = scalar[1][0];min[1] = scalar[1][0];for (int r = 0; r < 2; r++) {for (int j = 0; j < 4; j++) {if (scalar[r][j] >= max[r]) {max[r] = scalar[r][j];} else if (scalar[r][j] <= min[r]) {min[r] = scalar[r][j];}}}if ((min[1] <= max[0]) || (max[1] >= min[0])) {return(true);}}return(false);}public static void main(String[] args) {Rectangle[] rect = new Rectangle[2];Point[] r1Point = new Point[4];Point[] r2Point = new Point[4];r1Point[0] = new Point(10, 10);r1Point[1] = new Point(20, 10);r1Point[2] = new Point(20, 20);r1Point[3] = new Point(10, 20);r2Point[0] = new Point(30, 10);r2Point[1] = new Point(40, 10);r2Point[2] = new Point(40, 20);r2Point[3] = new Point(30, 20);rect[0] = new Rectangle(r1Point[0], r1Point[1], r1Point[2], r1Point[3]);rect[1] = new Rectangle(r2Point[0], r2Point[1], r2Point[2], r2Point[3]);if (checkCollision(rect[0], rect[1])) {System.out.println("Collision!");}}}Help is greatly appreciated!   
  Shouldn't you be returning true if and only if all of the projections overlap, and be returning false if any of the projections don't overlap?  It looks like you're returning true too early (meaning you haven't checked all the axes).  Since there are really only two axes you're checking I don't know if this is your problem, but it may be.Try running the algorithm with pencil and paper (and don't look at your code when you do it, you don't want to be following buggy code), and then step through the program with your debugger.  Assuming you get the correct result with your pencil and paper, you should be able to find out where you went wrong in your code.   ;  I've fixed this now.  The problem was I was calculating some of the axes wrong and also I was returning true whenever it overlapped on any axis, which you mentioned.  Thanks for looking.   