15 - Separating Axis Theorem/script.js
//applying the separating axis theorem on two objects

applying the separating axis theorem on two objects
applying the separating axis theorem on two objects
function sat(o1, o2){
    axes1 = [];
    axes2 = [];
    axes1.push(o1.dir.normal());
    axes1.push(o1.dir);
    axes2.push(o2.dir.normal());
    axes2.push(o2.dir);
    let proj1, proj2 = 0;
    for(let i=0; i<axes1.length; i++){
        proj1 = projShapeOntoAxis(axes1[i], o1);
        proj2 = projShapeOntoAxis(axes1[i], o2);
        let overlap = Math.min(proj1.max, proj2.max) - Math.max(proj1.min, proj2.min);
        if (overlap < 0){
            return false;
        }
    };
    for(let i=0; i<axes2.length; i++){
        proj1 = projShapeOntoAxis(axes2[i], o1);
        proj2 = projShapeOntoAxis(axes2[i], o2);
        overlap = Math.min(proj1.max, proj2.max) - Math.max(proj1.min, proj2.min);
        if (overlap < 0){
            return false;
        }
    };
    return true;
}
function sat ( o1 , o2 ) { axes1 = [ ] ; axes2 = [ ] ; axes1 . push ( o1 . dir . normal ( ) ) ; axes1 . push ( o1 . dir ) ; axes2 . push ( o2 . dir . normal ( ) ) ; axes2 . push ( o2 . dir ) ; let proj1 , proj2 = 0 ; for ( let i = 0 ; i < axes1 . length ; i ++ ) { proj1 = projShapeOntoAxis ( axes1 [ i ] , o1 ) ; proj2 = projShapeOntoAxis ( axes1 [ i ] , o2 ) ; let overlap = Math . min ( proj1 . max , proj2 . max ) - Math . max ( proj1 . min , proj2 . min ) ; if ( overlap < 0 ) { return false ; } } ; for ( let i = 0 ; i < axes2 . length ; i ++ ) { proj1 = projShapeOntoAxis ( axes2 [ i ] , o1 ) ; proj2 = projShapeOntoAxis ( axes2 [ i ] , o2 ) ; overlap = Math . min ( proj1 . max , proj2 . max ) - Math . max ( proj1 . min , proj2 . min ) ; if ( overlap < 0 ) { return false ; } } ; return true ; }
applying the separating axis theorem on two objects
applying the separating axis theorem on two objects