mIRC Home    About    Download    Register    News    Help

Print Thread
#485 09/12/02 07:15 AM
Joined: Dec 2002
Posts: 3
E
Ed_ Offline OP
Self-satisified door
OP Offline
Self-satisified door
E
Joined: Dec 2002
Posts: 3
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..

#486 09/12/02 10:45 AM
Joined: Dec 2002
Posts: 14
N
Pikka bird
Offline
Pikka bird
N
Joined: Dec 2002
Posts: 14
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.

#487 09/12/02 11:40 AM
Joined: Dec 2002
Posts: 3
E
Ed_ Offline OP
Self-satisified door
OP Offline
Self-satisified door
E
Joined: Dec 2002
Posts: 3
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..

#488 09/12/02 08:55 PM
Joined: Dec 2002
Posts: 3
E
Ed_ Offline OP
Self-satisified door
OP Offline
Self-satisified door
E
Joined: Dec 2002
Posts: 3
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)), $&
    %z = $calc($atan($calc(%y / %x)) * 180 / $pi), %deg
  if ($1 < $3) { %deg = 270 }
  if ($1 > $3) { %deg = 90 }
  if ($2 < $3) { %deg = 0 }
  if ($2 > $3) { %deg = 180 }
  if ($1 < $3) && ($2 < $4) { %deg = 270 + %z }
  if ($1 < $3) && ($2 > $4) { %deg = 270 - %z }
  if ($1 > $3) && ($2 > $4) { %deg = 90 + %z }
  if ($1 > $3) && ($2 < $4) { %deg = 90 - %z }
  var %deg = $gettok(%deg,1,46)
  if (%deg == 180) && ($1 == $3) {
    if ($2 >= $4) %deg = 180
    else %deg = 0
  }
  if (%deg == 180) && ($1 != $3) {
    if ($1 >= $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...


Link Copied to Clipboard