mIRC Homepage

# mIRC/Math problem

Posted By: Ed_

## mIRC/Math problem - 09/12/02 07:15 AM

Hi, I have a picture window with 2 dots on it. I need too know the angle of the 2nd dot, in relation to the 1st dot, in degrees... here are the X Y Properties:

1st dot: X=100 Y=300
2nd dot: X=250 Y=12

What i'm really hoping is for is some kind of snippet, that I could pass any 2 sets of X Y co-ordinates too, and return back an Angle between 0 and 360 degrees. Thanks in advance..
Posted By: namnori

## Re: mIRC/Math problem - 09/12/02 10:45 AM

angle would be arctan(dy/dx). dy = 12-300 = -288. dx = 250-100=150.
dy/dx is the slope between the two points, or -288/150 pixels.
take the arctan of that, and you get about -62.488 degrees. We double check to make sure the quadrants are right (otherwise we would have to throw in 180 degrees).

arctan in mIRC is \$atan, but it uses radians. To remember how to go back and forth between degrees and radians, remember that a circle is 360 degrees and 2*pi radians. so 360 degrees = 2*pi radians, or 180 degrees = pi radians. For the first 1.24 trillion places of pi, find this guy

for reference, 0 degrees would be to the right of the first point.
Posted By: Ed_

## Re: mIRC/Math problem - 09/12/02 11:40 AM

Ok... Thanks very much.

\$atan has a .deg property which i assume is intended to return the result in Degrees. So the solution should be:

//echo -a \$atan(-288 / 150).deg

However, this returns: -1.374417
So i am stuck at this invalid result..
Posted By: Ed_

## Re: mIRC/Math problem - 09/12/02 08:55 PM

Ok.. I found a rather clumbsy method that does what I want, So i'll post here for the benefit of others who may want it:

Code:
```
alias Degrees {
var %x = \$abs(\$calc(\$1 - \$3)), %y = \$abs(\$calc(\$2 - \$4)), \$&amp;
%z = \$calc(\$atan(\$calc(%y / %x)) * 180 / \$pi), %deg
if (\$1 &lt; \$3) { %deg = 270 }
if (\$1 &gt; \$3) { %deg = 90 }
if (\$2 &lt; \$3) { %deg = 0 }
if (\$2 &gt; \$3) { %deg = 180 }
if (\$1 &lt; \$3) &amp;&amp; (\$2 &lt; \$4) { %deg = 270 + %z }
if (\$1 &lt; \$3) &amp;&amp; (\$2 &gt; \$4) { %deg = 270 - %z }
if (\$1 &gt; \$3) &amp;&amp; (\$2 &gt; \$4) { %deg = 90 + %z }
if (\$1 &gt; \$3) &amp;&amp; (\$2 &lt; \$4) { %deg = 90 - %z }
var %deg = \$gettok(%deg,1,46)
if (%deg == 180) &amp;&amp; (\$1 == \$3) {
if (\$2 &gt;= \$4) %deg = 180
else %deg = 0
}
if (%deg == 180) &amp;&amp; (\$1 != \$3) {
if (\$1 &gt;= \$3) %deg = 90
else %deg = 270
}
return %deg
}
```

It works like this: \$degrees(X1,Y1,X2,Y2)
X2 and Y2 should be the X Y co-ordinates of the Main dot.
for example:
//echo -a \$degrees(250,12,100,300)

It's not the best method, but sufficient for my purposes...