Maths Question

Help section from before the user variable changes that broke all macros

Moderator: MacroQuest Developers

User avatar
Fippy
a snow griffon
a snow griffon
Posts: 499
Joined: Tue Jul 16, 2002 10:42 am

Maths Question

Post by Fippy » Sat Sep 21, 2002 6:54 am

Given the following situation

Code: Select all


          Y
          |
          |
          |
          |
          |
          |
          |     *b(30,70)
          |      \           _
          |        \         /|
          |        d \     /
          |            \ /
          |             *a(60,30)
          |              
          |
          |
----------+------------------- X
          |
          |
          |
          

Given the x,y of point a and point b and knowing the angle point a is heading and length d can be calculated how do you calculate the heading to point b ??

anybody good a trig ??
Fippy

Trying to write a headingto function for a loc for use in my nearly completed hunter script.

User avatar
DeathSpiral
a ghoul
a ghoul
Posts: 95
Joined: Thu Aug 22, 2002 6:31 pm

Post by DeathSpiral » Sat Sep 21, 2002 7:15 am

I thought that if you didn't use the nopredict option to /face, it would face the interception point between yourself and the target. I could be completely wrong though.
I am orc pawn, hear me yell for centurians...

eq_freak
a ghoul
a ghoul
Posts: 105
Joined: Mon Jun 24, 2002 7:17 am

Post by eq_freak » Sat Sep 21, 2002 8:21 am

Why not just use the /face loc <y>,<x> command that is builtin?

You need the heading for some other calculation?

Valerian
a grimling bloodguard
a grimling bloodguard
Posts: 709
Joined: Sun Jul 28, 2002 3:29 am

Post by Valerian » Sat Sep 21, 2002 9:23 am

yeah, another calculation? like... wanting to run a certain number of degrees to the side of the target at all times? like... similar to the way a bard kites? *hmm*

nope, can't help ya... no clue about all that uber math stuff =)

User avatar
Fippy
a snow griffon
a snow griffon
Posts: 499
Joined: Tue Jul 16, 2002 10:42 am

Post by Fippy » Sat Sep 21, 2002 9:36 am

Deathspiral - point b aint my target, its a point i want to run around with out getting too close.

eq_freak - yeah need the heading for another reason, so I can set a heading that will run around point b

Valerian - Nice though but in this case no not for bard kiting.

What I am trying to do is set up an array that will hold a loc and a radius, These areas are areas to avoid running into. Lavapits, huts, or lakes for example. Gonna have a check that will run down the array and see if my current loc is within the radius, if so change my heading to the left or right to avoid the obstacle.

I did try doing a /face to point b to get the loc but due to lag and such i just end up bouncing around until i am facing away from the loc so i could never get past it.

eq_freak
a ghoul
a ghoul
Posts: 105
Joined: Mon Jun 24, 2002 7:17 am

Post by eq_freak » Sat Sep 21, 2002 12:09 pm

Damn, very depressing how much math you can forget in 10 years lol, and now I got a headache from trying to remember it :p

Anyway, you can check out eqlib.cpp and find the code that Plazmic uses to calculate the heading if you look in the code for /face loc.

Code: Select all

			gFaceAngle = (
				atan2(pSpawnClosest->X - pChar->X, 
				       pSpawnClosest->Y - pChar->Y)
				* 256.0f / PI);

		if (gFaceAngle>=512.0f) gFaceAngle -= 512.0f;
		if (gFaceAngle<0.0f) gFaceAngle += 512.0f;
(note: rewrite it to use 360 degrees, this example is using EQs internal 512 degree system)
(note2: pSpawnClosest in this example is set to the loc you wish to face)

He uses the atan2 function though, which you dont have access to in MQ, only atan. If you look here, you can find the code needed to implement the atan2 function using atan:

http://www.introl.com/introl-demo/Libra ... atan2.html

Its possible there exist a simpler formula, but I hope some of that helped.

User avatar
Fippy
a snow griffon
a snow griffon
Posts: 499
Joined: Tue Jul 16, 2002 10:42 am

Post by Fippy » Fri Sep 27, 2002 10:01 am

Forgive my noob question but I aint a C programer at all so most of that linked stuff sorta went over my head. I pressume that this is the bit of code I would turn into MQ script to get a working atan2 function.

Code: Select all

atan2(y, x):= atan(y/x)                          if x > 0,
              sign(y)*(pi - atan(|y/x|))         if x < 0,
              0                                  if x = y = 0, or
              sign(y)*pi/2                       if x = 0 y.
if so what does the sign(y) bit mean, cant seem to find a reference to it on google also the |y/x| bit ??

Fippy

Plazmic
The One
The One
Posts: 800
Joined: Fri Jun 14, 2002 12:31 am
Contact:

Post by Plazmic » Fri Sep 27, 2002 11:44 am

sign(a) :=
-1 If a < 0
0 If a = 0
1 If a > 0
- Plazmic

User avatar
Fippy
a snow griffon
a snow griffon
Posts: 499
Joined: Tue Jul 16, 2002 10:42 am

Post by Fippy » Sat Sep 28, 2002 9:36 am

OK not anywhere near my PC (on holiday) but this is my attempt at atan2 in MQ script, can anybody check this is correct? Ill check it myself on Monday when I get back home otherwise.

Code: Select all

 
/sub atan2
   /if n $p0==0 /return 0
   /if n $p1==0 /return 0
   /if n $p0>0 /return $atan($p1/$p0)
   /if n $p0<0 {
      /call sign $p1
      /return $calc($return*$calc(3.142-$atn($abs($calc($p1/$p0)))))
   }
/return 0

/sub sign
 /if n $p0<0 /return -1
 /if n $p0==0 /return 0
 /if n $p0>0 /return 1
/return 0

Fippy

User avatar
Fippy
a snow griffon
a snow griffon
Posts: 499
Joined: Tue Jul 16, 2002 10:42 am

Post by Fippy » Mon Sep 30, 2002 10:56 am

Looks like $heading is in the IRC relase so i dont have to test this now.

Woot! Gonna try and get my area avoidance script written now.

Fippy