# Inverse Tangent?!?

**URL:** <https://forum.kirupa.com/t/inverse-tangent/42540>\
**Category:** flash\
**Created:** [February 10, 2004, 4:53am UTC](https://forum.kirupa.com/t/inverse-tangent/42540 "2004-02-10T04:53:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maniaci](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Maniaci](https://forum.kirupa.com/u/Maniaci)\
**Post date:** [February 10, 2004, 4:53am UTC](https://forum.kirupa.com/t/inverse-tangent/42540/1 "2004-02-10T04:53:58Z")

</div>

I’m trying to get an angle out of the X and the Y values of the mouse. If there is an inverse tangent, it would be someingthing like invtan(x,y).

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2004, 7:33am UTC](https://forum.kirupa.com/t/inverse-tangent/42540/2 "2004-02-10T07:33:39Z")

</div>

i think you’re looking for Math.atan2()

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2004, 11:01am UTC](https://forum.kirupa.com/t/inverse-tangent/42540/3 "2004-02-10T11:01:17Z")

</div>

be sure to use y first

Math.atan2(y,x)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 11, 2004, 1:20am UTC](https://forum.kirupa.com/t/inverse-tangent/42540/4 "2004-02-11T01:20:43Z")

</div>

Tried that and, according to the AS dictionary in MX,

> The return value represents the angle opposite the opposite angle of a right triangle, where x is the adjacent side length and y is the opposite side length.

so wouldn’t i just take the Math.atan2(x,y), add 90, then subtract it from 180 to find the third angle?

Here is the code:  
[AS]  
onClipEvent(enterFrame){  
mouseX = \_root.\_xmouse;  
mouseY = \_root.\_ymouse;

invTan = Math.atan2(mouseY,mouseX);  
theRotation = 180-(invTan+90);

\_root.test.text = theRotation;  
this.\_rotation = theRotation;  
}  
[/AS]

theRotation only returns a value from 89.0-91.0. Im more than likely overlooking something :h:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 11, 2004, 1:39am UTC](https://forum.kirupa.com/t/inverse-tangent/42540/5 "2004-02-11T01:39:10Z")

</div>

atan2 return value is in radians

```auto
onClipEvent(enterFrame){
	dx = _parent._xmouse - _x;
	dy = _parent._ymouse - _y;
	
	radians = Math.atan2(dy,dx);
	degrees = radians*180/Math.PI;
	
	_rotation = degrees;
}

```

And this assumes pointing right is 0 degrees so either start your clip pointing right or add (90 for example) from there to get it to face the mouse.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 11, 2004, 5:08am UTC](https://forum.kirupa.com/t/inverse-tangent/42540/6 "2004-02-11T05:08:57Z")

</div>

Awsome thanks, Senocular… i tried that but was missing the - \_x, and the - \_y when i was getting the x, y values of the mouse Ⓜ
