Check if it is possible to reach vector B by rotating vector A and adding vector C to it | Function to check if vector B is possible from vector A ; If d = 0 , then you need to add nothing to vector A ; for all four qua for all four quadrants ; Initialize all three vector coordinates
function _check ( a , b , p , q ) { var d = p * p + q * q ; if ( d == 0 ) return a == 0 && b == 0 ; else return ( a * p + b * q ) % d == 0 && ( b * p - a * q ) % d == 0 ; } function check ( a , b , x , y , p , q ) { if ( _check ( a - x , b - y , p , q ) || _check ( a + x , b + y , p , q ) || _check ( a - y , b + x , p , q ) || _check ( a + y , b - x , p , q ) ) return true ; else return false ; } var a = - 4 , b = - 2 ; var x = 0 , y = 0 ; var p = - 2 , q = - 1 ; if ( check ( a , b , x , y , p , q ) ) document . write ( " " ) ; else document . write ( " " ) ;