# Help with rotation formula

**URL:** <https://forum.kirupa.com/t/help-with-rotation-formula/188849>\
**Category:** Uncategorized\
**Created:** [May 11, 2006, 10:55am UTC](https://forum.kirupa.com/t/help-with-rotation-formula/188849 "2006-05-11T10:55:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SacrificialLamb](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@SacrificialLamb](https://forum.kirupa.com/u/SacrificialLamb)\
**Post date:** [May 11, 2006, 10:55am UTC](https://forum.kirupa.com/t/help-with-rotation-formula/188849/1 "2006-05-11T10:55:15Z")

</div>

at the moment it is not working at top left correct(about 10˚ of rotation at about 180˚ off) and bottom left is inverted (180˚ to much). I had all but top left working but when fixing that I broke the bottom left.  
It should make a top view of a man rotate to face the mouse. 0 rotation of the man he is facing down, this was unintentional the code was intended to make him face up but I didn’t mind  
This code is for a RPG that I am making for a beginner’s flash class

[http://www.ping.be/~ping1339/gonio.htm](http://www.ping.be/~ping1339/gonio.htm) (I added this link coz this is the referents I used to refresh my understanding of Trigonometry. Might be useful for some keen people)

> onClipEvent (load){  
> Cx = Stage.width/2  
> Cy = (Stage.height/2)- 30 //the 30 is to les on the inpact of the interface

}  
on (release){

```
//rotashon of man
if (_xmouse &gt;Cx && _ymouse&gt;=Cy){ //betwen 0 and 89 top right &#952;./_|
    Radian= ((Math.PI/2) - Math.atan( (_ymouse-Cy)/(_xmouse-Cx) ))
}
if (_xmouse &gt;=Cx && _ymouse&lt;Cy){//betwen 90 and 179 botom right &#952;`|_\
    Radian=(Math.PI/2) +((Math.PI/2) - (Math.atan((_xmouse-Cx)/(Cy-_ymouse))))
}
if (_xmouse <Cx && _ymouse<=Cy){//betwen 180 and 269 botom left /_|`&#952;

    Radian=(Math.PI/2) + (Math.atan((_xmouse+Cx)/(Cy-_ymouse)))
}

if (_xmouse &lt;= Cx && _ymouse &gt; Cy){//betwen 270 and 359 top left |_\.&#952;
    //Radian=((2*Math.PI) + ((Math.atan((_ymouse-Cy)/(Cx-_xmouse)))))
    Radian=((2*Math.PI)+(Math.PI/2) + ((Math.atan((_ymouse-Cy)/(Cx-_xmouse)))))
    
}
_global.man_angal= Radian*(360/(2*Math.PI)) //convert Radians to Degree
    
    
trace("Radian "+Radian)
trace("man_angal in deges "+_global.man_angal)

```

//send moveing instrucshons  
if (((Cx + 10)\> \_xmouse)||(Cx - 10)\< \_xmouse) {//test for minamin movement  
\_global.moveX = (\_xmouse-Cx)//send moveing instrucshons  
}  
if (((Cy + 10)\> \_ymouse) || (Cy - 10)\< \_ymouse) {//test for minamin movement  
\_global.moveY = (\_ymouse-Cy)  
}

}

---

<div class="post-metadata">

**Author:** ![SacrificialLamb](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@SacrificialLamb](https://forum.kirupa.com/u/SacrificialLamb)\
**Post date:** [May 11, 2006, 10:13pm UTC](https://forum.kirupa.com/t/help-with-rotation-formula/188849/2 "2006-05-11T22:13:38Z")

</div>

have fixed it now  
For any one that is interested here is the code now:

```php
    //rotashon of man
    if (_xmouse >Cx && _ymouse>=Cy){ //betwen 0 and 89 top right &#952;./_|
    trace("top right")
        Radian= ((Math.PI/2) - Math.atan( (_ymouse-Cy)/(_xmouse-Cx) ))
    }
    if (_xmouse >=Cx && _ymouse<Cy){//betwen 90 and 179 botom right &#952;`|_\
    trace("botom right")
        Radian=(Math.PI/2) +((Math.PI/2) - (Math.atan((_xmouse-Cx)/(Cy-_ymouse))))
    }
    if (_xmouse &lt;Cx && _ymouse&lt;=Cy){//betwen 180 and 269 botom left /_|`&#952;
trace("botom left")
        Radian=(Math.PI) + (Math.atan((Cx-_xmouse)/(Cy-_ymouse)))
    }
    
    if (_xmouse <= Cx && _ymouse > Cy){//betwen 270 and 359 top left |_\.&#952;
trace("top left")
        //Radian=((2*Math.PI)+(Math.PI/2) + ((Math.atan((_ymouse-Cy)/(Cx-_xmouse)))))
        Radian=( -(Math.PI/2)+((Math.atan((_ymouse-Cy)/(Cx-_xmouse)))))
        
    }
    _global.man_angal= Radian*(360/(2*Math.PI)) //convert Radians to Degree

```

but i don’t really understand how what i did fixed it. i changed [COLOR=#000000]COLOR=#007700[/COLOR][/COLOR][COLOR=#000000][COLOR=#007700]+[/COLOR][/COLOR][COLOR=#000000]COLOR=#007700[/COLOR][/COLOR]with[COLOR=#000000][COLOR=#007700]-([/COLOR][COLOR=#0000bb]Math[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]PI[/COLOR][COLOR=#007700]/[/COLOR][COLOR=#0000bb]2[/COLOR][COLOR=#007700])[/COLOR][/COLOR] this is -90° rather than +270° which should give the same orientation in positive ° as apposed to negative
