# Counting Radians

**URL:** https://forum.kirupa.com/t/counting-radians/327667
**Category:** flash
**Created:** [March 18, 2012, 7:50am UTC](https://forum.kirupa.com/t/counting-radians/327667 "2012-03-18T07:50:48Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![scorp200](https://avatars.discourse-cdn.com/v4/letter/s/ba9def/32.png) [@scorp200](https://forum.kirupa.com/u/scorp200)
#### Post date: [March 18, 2012, 7:50am UTC](https://forum.kirupa.com/t/counting-radians/327667/1 "2012-03-18T07:50:48Z")

</div>

I have an object that rotates based on the mouse position  
and I’m trying to count the degrees as it rotates.  
for example if i rotate 200 degrees cww the degree measurement is 200  
if i will rotate another 350 degrees cww the degree measurement will be 550  
now if i rotate 150 cw the measurement will be 400 now.

I have this code: (it counts radians, but it is the same idea)  
p1 = mouse position

```php
   
             theX = p1.x - 250;
             theY = p1.y - 250;
             radian = -Math.atan2(theY, theX);
             if (mouseY <= 250)
            {
                total_radian += Math.abs(radian) - old_radian;
            }
            else if (mouseY >= 250)
            {
                total_radian += old_radian - Math.abs(radian);
             }

```

the problem is that if i rotate quickly it will miscalculate it.  
any suggestions for better counting?
