# atan2 weird behavior

**URL:** <https://forum.kirupa.com/t/atan2-weird-behavior/238588>\
**Category:** flash\
**Created:** [September 12, 2007, 9:25pm UTC](https://forum.kirupa.com/t/atan2-weird-behavior/238588 "2007-09-12T21:25:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chan\_arantes](https://avatars.discourse-cdn.com/v4/letter/c/57b2e6/32.png) [@chan\_arantes](https://forum.kirupa.com/u/chan_arantes)\
**Post date:** [September 12, 2007, 9:25pm UTC](https://forum.kirupa.com/t/atan2-weird-behavior/238588/1 "2007-09-12T21:25:23Z")

</div>

Hi,  
i’m using a script to generate these segments and position them in a theo jansen mechanism but something is really not working…

![](http://indicedesign.com.br/chan/atan2.png)

```auto

// worked fine, the "a" segment
var dx = a.x - g.getPin().x;
var dy = a.y - g.getPin().y;
a.rotation = Math.atan2(dx, dy) * 180 / Math.PI;
 
// didn't work, the "e" segment
dx = d.x - e.x;
dy = d.getPin().y - c.getPin().y;
e.rotation = Math.atan2(dx, dy) * 180 / Math.PI;

```

where getPin() method returns an object that contain the position of the “object´s pin”

an example

e.width = 77;  
w.x = 100  
trace(e.getPint().x) // outputs 177

I´m trying to get the correct angle of e segment in order to make it snap to the “d” lower pin  
I tried many ways using these values, the difference, the inverse difference, and all failed

what i’m i doing wrong?
