# Sloppy method /math help

**URL:** <https://forum.kirupa.com/t/sloppy-method-math-help/318882>\
**Category:** Uncategorized\
**Created:** [February 2, 2011, 5:22pm UTC](https://forum.kirupa.com/t/sloppy-method-math-help/318882 "2011-02-02T17:22:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbo](https://avatars.discourse-cdn.com/v4/letter/t/7feea3/32.png) [@tbo](https://forum.kirupa.com/u/tbo)\
**Post date:** [February 2, 2011, 5:22pm UTC](https://forum.kirupa.com/t/sloppy-method-math-help/318882/1 "2011-02-02T17:22:13Z")

</div>

if you picture swiping the mouse from the center of an octagon outward, i want to calculate which one of the 8 sides you are within.  
If i have the angle in degrees, i currently state:

```auto

if (degrees > -22.5 && degrees <= 22.5)
{
    txt.text = "1";
}
else if (degrees > -22.5 && degrees <= 67.5)
{
    txt.text = "2";
}
else if (degrees > 67.5 && degrees <= 112.5)
{
    txt.text = "3";
}
else if (degrees > 112.5 && degrees <= 157.5)
{
    txt.text = "4";
}
else if ((degrees > 157.5 && degrees <= 180)|| (degrees >= -180 && degrees <=-157.5))
{
    txt.text = "5";
}
else if (degrees > -157.5 && degrees <=-112.5)
{
    txt.text = "6";
}
else if ( degrees >-112.5 && degrees<=-67.5)
{
    txt.text = "7";
}
else if (degrees>-67.5&& degrees<=-22.5)
{
    txt.text = "8";
}

```

This of course does work, but it seems a little extensive to check up to 8 statements to find this answer. What would be a better way to approach this?

thanks
