Created
July 11, 2020 17:55
-
-
Save EduardoJM/0d7e1fbde695c445bb65c3b2db0c8653 to your computer and use it in GitHub Desktop.
Separating Axis Theorem Helper Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function buildEdges(vertices) { | |
const edges = []; | |
if (vertices.length < 3) { | |
console.error("Only polygons supported."); | |
return edges; | |
} | |
for (let i = 0; i < vertices.length; i++) { | |
const a = vertices[i]; | |
let b = vertices[0]; | |
if (i + 1 < vertices.length) { | |
b = vertices[i + 1]; | |
} | |
edges.push({ | |
x: (b.x - a.x), | |
y: (b.y - a.y), | |
}); | |
} | |
return edges; | |
} | |
function intervalDistance(minA, maxA, minB, maxB) { | |
if (minA < minB) { | |
return (minB - maxA); | |
} | |
return (minA - maxB); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment