This might be more of a math question, but it relates to the development of a simple physics engine I am trying to create.
I have been stumped on this for about a week now, and have been unable to find an answer in any of the SAT tutorials. (http://www.metanetsoftware.com/technique/tutorialA.html#toc, http://gamedevelopment.tutsplus.com/tutorials/collision-detection-using-the-separating-axis-theorem--gamedev-169, etc.)
I understand how SAT is supposed to work, however I am little confused on the math. First, I am finding my normals like so:
Block.prototype.findNormals = function () {
var axisVectors = new Array();
var vertices = this.Properties.Vertices;
var keys = Object.keys(vertices)
for( var i = 0; i < keys.length; i++) {
var last = {x: 0, y: 0};
axisVectors.push({xComponent: -(vertices[keys[i]].y - last.y), yComponent: (vertices[keys[i]].x - last.x) });
last = {x: this.x, y: this.y};
}
return axisVectors;
}
I am then precede to project each vertex of the shapes I am testing on those normals.
The problem occurs, and the part of the math that I am not fully understanding, is when I have a situation like so:
axis = (-5, 6)
vertex = (6, 5)
math.dot(vertex, axis)
This results in 0.
Thus my min value for shape1 is always 0. And this results in a false collision.
Can anyone explain the math a little better?