Created
March 28, 2018 14:24
-
-
Save d3x0r/fe7287d4aa8e8046e1c2c449d457755e to your computer and use it in GitHub Desktop.
compare coords and get octant...
This file contains hidden or 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 x = 13 | |
var y = 12; | |
var centerX = 10; | |
var centerY = 10; | |
function getOctant( x, y ) { | |
x-=centerX; | |
y -= centerY; | |
var dir = 0; | |
if( x < 0 ) { | |
if( y < 0 ) { | |
dir = 4; | |
if( -x < -y ) dir += 1; | |
}else { | |
dir = 2; | |
if( -x > y ) dir += 1; | |
} | |
} else | |
if( y < 0 ) { | |
dir = 6; | |
if( x > -y ) dir += 1; | |
} | |
else{ | |
dir = 0; | |
if( y > x ) dir += 1; | |
} | |
return dir; | |
} | |
console.log( getOctant( 17, 15 ) ); | |
console.log( getOctant( 12, 25 ) ); | |
console.log( getOctant( 8, 25 ) ); | |
console.log( getOctant( 3, 15 ) ); | |
console.log( getOctant( 5, 8 ) ); | |
console.log( getOctant( 5, 2 ) ); | |
console.log( getOctant( 15, 2 ) ); | |
console.log( getOctant( 15, 8 ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment