Created
April 17, 2015 15:17
-
-
Save CLOUGH/f6a47adaafcfb52f4d29 to your computer and use it in GitHub Desktop.
Check to see if a list of coords form a square
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
var isSquare = function(cords){ | |
console.log(cords); | |
for(var i=0;i<cords.length-1;i++){ | |
var currentVector = Math.pow(cords[i].x-cords[i+1].x,2) + Math.pow(cords[i].y-cords[i+1].y,2); | |
if(i==0){ | |
previousVector = currentVector; | |
console.log(currentVector, previousVector); | |
} | |
else{ | |
console.log(currentVector, previousVector); | |
if( currentVector*2 == previousVector || currentVector/2 == previousVector || currentVector==previousVector){ | |
} else{ | |
return false; | |
} | |
} | |
} | |
return true; | |
} | |
var cords = [ | |
{ x:8, y:3 }, | |
{ x:7, y:8 }, | |
{ x:2, y:7 }, | |
{ x:3, y:2} | |
]; | |
console.log('Is Funtion: '+isSquare(cords)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment