public Line bestEdge(Vector2d collisionNormal) // FIXME { double max = -Double.MAX_VALUE; int index = -1; System.out.println(collisionNormal); for (int i = 0; i < vertices.size(); i++) { double projection = collisionNormal.dot(vertices.get(i)); if (projection > max) { max = projection; index = i; } } // now we find the most perpendicular edge Vector2d v = vertices.get(index); Vector2d v1, v0; if (index + 1 == vertices.size()) v1 = vertices.get(0); else v1 = vertices.get(index + 1); if (index == 0) v0 = vertices.get(vertices.size() - 1); else v0 = vertices.get(index - 1); Vector2d left = new Vector2d(v.x - v1.x, v.y - v1.y); Vector2d right = new Vector2d(v.x - v0.x, v.y - v0.y); System.out.println("right: " + right + " left: " + left); if (Math.abs(right.dot(collisionNormal)) <= Math.abs(left.dot(collisionNormal))) { // System.out.println("return right"); v0.draw(); v.draw(); return new Line(v0, v); } else { // System.out.println("return left"); v.draw(); v1.draw(); return new Line(v, v1); } }