Please show me a more elegant way to do this
<p>To me, this is the obvious way to do this: given a start point and an end point, tell me if the end point is up / down / left / upleft / downright... etc of the start point. Heres the core of my logic :</p>

<pre><code>function getSector() {
    var y = startY - endY;
    var x = startX - endX;
    var angle = Math.atan2(y,x) * 57.29578;//~57 deg per radian
    //atan2(y,x) returns a num between -PI and PI, represents angle in radians
    console.log("angle:" + angle);
    if( (angle &gt; -22.5) &amp;&amp; (angle &lt; 22.5) ) attackDir = "left";
    if( (angle &gt; 22.5) &amp;&amp; (angle &lt; 67.5) ) attackDir = "upleft";
    if( (angle &gt; 67.5) &amp;&amp; (angle &lt; 112.5) ) attackDir = "up";
    if( (angle &gt; 112.5) &amp;&amp; (angle &lt; 157.5) ) attackDir = "upright";
    if( (angle &gt; 157.5) &amp;&amp; (angle &lt;= 180) ) attackDir = "right";
    if( (angle &gt; -179) &amp;&amp; (angle &lt;= -157) ) attackDir = "right";
    if( (angle &gt; -157) &amp;&amp; (angle &lt; -112.5) ) attackDir = "downright";
    if( (angle &gt; -112.5) &amp;&amp; (angle &lt; -67.5) ) attackDir = "down";
    if( (angle &gt; -67.5) &amp;&amp; (angle &lt; -22.5) ) attackDir = "downleft";
    console.log("attackDir:" + attackDir);
}
</code></pre>

<p>I'm interested in seeing a better way, but more so, HOW you arrived at that way.</p>

<p>I guess a key of sorts would be in order :
left = 0 
up = 90 
right = 179 OR -179 (down is like a negative mirror of up)
down = -90</p>
