Help to calculate angle

Ask gaming related questions (AHK v1.1 and older)
Nadaleh
Posts: 26
Joined: 26 Aug 2021, 15:04

Help to calculate angle

09 Dec 2021, 00:16

Hi , i need help with calculating angle to make a movement in-game World of Warcraft.

Code: Select all

F5::


xx1 = 1
yy1 = 2.5
xx2 = 3
yy2 = 3




Angle1(xx1, yy1, xx2, yy2) {
	return ACos((xx1 * xx2 + yy1 *yy2) / (Sqrt(xx1**2 + yy1**2) * Sqrt(xx2**2 + yy2**2))) * 57.2957795
}


MsgBox, % Angle1(xx1,yy1,xx2,yy2)


return

f6::
x1=26.77
y1=77.00
x2=26.71
y2=75.96
MsgBox, % Angle(x1,y1,x2,y2)



Angle(x1, y1, x2, y2) {
	return ACos((x1 * x2 + y1 * y2) / (Sqrt(x1**2 + y1**2) * Sqrt(x2**2 + y2**2))) * 57.2957795
}

return

F10::
reload
In this example "F5" calculate existing sample from internet and it show a angle as 23degree , when i try to use same for game its show fake data for example an angle in 0.2 degree.
x1,y1 is my current pos and x2,y2 destination pos. i test in-game navigation and when i turn my character to 0 degree and start moving only y pos is changed, so navigation inside game is correct.
Rohwedder
Posts: 7630
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Help to calculate angle

09 Dec 2021, 06:12

Hallo,
try:

Code: Select all

Rad2Deg := 45/Atan(1) ; = 180°/π 
; this factor converts radians to degrees
F5::
xx1 = 1
yy1 = 2.5
xx2 = 3
yy2 = 3
Angle1 := Atan(yy1/xx1)*Rad2Deg ;68.198591°
Angle2 := Atan(yy2/xx2)*Rad2Deg ;45.000000°
MsgBox,% Angle1 - Angle2 "°"	;23.198591°
Return
F6::
x1=26.77
y1=77.00
x2=26.71
y2=75.96
Angle := Atan((Y2-Y1)/(X2-X1))*Rad2Deg
MsgBox,% Angle "°" ;86.698134°
Return
Your character moved approximately vertically upwards (~90°)
Nadaleh
Posts: 26
Joined: 26 Aug 2021, 15:04

Re: Help to calculate angle

09 Dec 2021, 06:42

@Rohwedder
ty , i hope this help.
Nadaleh
Posts: 26
Joined: 26 Aug 2021, 15:04

Re: Help to calculate angle

09 Dec 2021, 06:49

Rohwedder wrote:
09 Dec 2021, 06:12

Angle1 := Atan(yy1/xx1)*Rad2Deg ;68.198591°
Angle2 := Atan(yy2/xx2)*Rad2Deg ;45.000000°
what is this 2 angles? its compared to 0.0 coordinate?
Rohwedder
Posts: 7630
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Help to calculate angle

09 Dec 2021, 07:25

No idea! I don't know your existing sample from internet.
I imagined your points (1,2.5), (3,3) and the only angle that corresponded to about 23° was the difference angle with respect to the origin (0,0). This angle corresponds exactly to the result of your calculation.
Nadaleh
Posts: 26
Joined: 26 Aug 2021, 15:04

Re: Help to calculate angle

10 Dec 2021, 01:25

Update. map below shows that default formula to calculate angle isn't working, because X-axis is 25% longer than Y-axis.
and i dont get how to calculate angle betwen 2 coordinates on map, default formula only work is Coordinate Grid have a default square shape.
Attachments
unknown (1).png
unknown (1).png (1.17 MiB) Viewed 1338 times
Dixtroy
Posts: 12
Joined: 05 Jul 2019, 03:40

Re: Help to calculate angle

13 Dec 2021, 04:25

Direction angle is in radiant, that means with [x,y] coordiantes [1,0] is 0 or 2PI, [0,-1] 1/2 PI , [-1,0] PI , [0,1] 2/3 PI, in a normal coordinate system. You have mirrored system to x axis, so +y is down -y is up.
This code still gives back normal radiant angles, North is 2/3 PI, south is 1/2 PI, and so on.

Code: Select all

	
direction(x,y)
{       
	R:=[[1,1,2], [1,0,0],[1,0,0]];
	return R[y<0 ? 0 : (y==0 ? 1 : 2)][x<0 ? 0 : (x==0 ? 1 : 2)]*3.141592653589793+ATan(y/x);
}
If the x axis is 25% longer, it means 4x coordinate and 5y coordinate makes a square?
Then call function like this:

Code: Select all

angle:=direction(x/1.25, y)
If you want to get back degree informations this code helps:

Code: Select all

radian2degree(mit)
{
	F:={"f":0, "p":0, "m":0, "R":mit, "TF":mit/3.141592653589793*180, "F":'' };
	F.f:=floor(F.TF);
	F.p:=floor((F.TF-F.f)*60);
	F.m:=round((F.TF-F.p/60-F.f)*6000);
	F.F:=F.f '°' substr(('00'+F.p),-1) "'" substr(('00'+F.m),-1) '"';
	return F.F;
}
I think you want to run with your character to a special direction, so you have to determine route flag coordinates, and control your character with buttons, till reach the point. For example you are in 0,100 and want to run 50,50, push right and up and when reach 60,50, then push only the up, and let the angles.
Nadaleh
Posts: 26
Joined: 26 Aug 2021, 15:04

Re: Help to calculate angle

13 Dec 2021, 08:03

Dixtroy wrote:
13 Dec 2021, 04:25
Direction angle is in radiant, that means with [x,y] coordiantes [1,0] is 0 or 2PI, [0,-1] 1/2 PI , [-1,0] PI , [0,1] 2/3 PI, in a normal coordinate system. You have mirrored system to x axis, so +y is down -y is up.
This code still gives back normal radiant angles, North is 2/3 PI, south is 1/2 PI, and so on.

Code: Select all

	
direction(x,y)
{       
	R:=[[1,1,2], [1,0,0],[1,0,0]];
	return R[y<0 ? 0 : (y==0 ? 1 : 2)][x<0 ? 0 : (x==0 ? 1 : 2)]*3.141592653589793+ATan(y/x);
}
If the x axis is 25% longer, it means 4x coordinate and 5y coordinate makes a square?
yes , but i think its 5X and 4Y make a 100.100 square
Then call function like this:

Code: Select all

angle:=direction(x/1.25, y)
If you want to get back degree informations this code helps:

Code: Select all

radian2degree(mit)
{
	F:={"f":0, "p":0, "m":0, "R":mit, "TF":mit/3.141592653589793*180, "F":'' };
	F.f:=floor(F.TF);
	F.p:=floor((F.TF-F.f)*60);
	F.m:=round((F.TF-F.p/60-F.f)*6000);
	F.F:=F.f '°' substr(('00'+F.p),-1) "'" substr(('00'+F.m),-1) '"';
	return F.F;
}
I think you want to run with your character to a special direction, so you have to determine route flag coordinates, and control your character with buttons, till reach the point. For example you are in 0,100 and want to run 50,50, push right and up and when reach 60,50, then push only the up, and let the angles.
Yeah i wana make a movement , with OCR i read my current location(50,50) and i want to move to another location (60,50), wasted few days and all for nothing , after this i notice that coordinate grid isn't square, and can u explain what is code on top do? i dont understand it at all. What is F? F.f?
Dixtroy
Posts: 12
Joined: 05 Jul 2019, 03:40

Re: Help to calculate angle

13 Dec 2021, 13:31

At first, you do not needs ocr, wow has a lot of addon for example this:

https://www.curseforge.com/wow/addons/map-coords

Ok, so there is an information from your actual position. A I remember you can moving with press mouse right and left click, and rotate with A - D buttons?

You needs a loop, with exit when coordinates are +-5 as you needs it (Xt, Yt).
in loop, read coordinates (Xs, Ys), log it, move with mouse buttons, sleep 1000, then check coordinates (Xn, Yn).

Theory of run, with pseudocode:

Code: Select all

check X
if ( Xt-Xs>Xt-Xn ) 
 wrong direction, rotate needs: if Yt-Xs>Yt-Yn then 180 else 10°clockwise
else
 if (Xt-Xn<5)
  you are here
 else
 move forward

check Y
if ( Yt-Ys>Yt-Yn ) 
 wrong direction, rotate needs: if Xt-Xs>Xt-Xn then 180 else 10°counterclockwise
else
 if (Yt-Yn<5)
  you are here
 else
 move forward
Dixtroy
Posts: 12
Joined: 05 Jul 2019, 03:40

Re: Help to calculate angle

13 Dec 2021, 13:57

Yeah i wana make a movement , with OCR i read my current location(50,50) and i want to move to another location (60,50), wasted few days and all for nothing , after this i notice that coordinate grid isn't square, and can u explain what is code on top do? i dont understand it at all. What is F? F.f?
Forget it. Do not waste your time with OCR.
Grab a map, what let you moving when shows you with a blue point middled arrow, like this:
https://www.curseforge.com/wow/addons/leatrix-maps-classic/screenshots

For example you are at 340 200, founded arrow Imagesearch, and want to run 200 530 Goldshire. Run a direction 1s and check image on map again. Use screen pixel positions, as coordinates..
Nadaleh
Posts: 26
Joined: 26 Aug 2021, 15:04

Re: Help to calculate angle

14 Dec 2021, 00:32

Dixtroy wrote:
13 Dec 2021, 13:57
Yeah i wana make a movement , with OCR i read my current location(50,50) and i want to move to another location (60,50), wasted few days and all for nothing , after this i notice that coordinate grid isn't square, and can u explain what is code on top do? i dont understand it at all. What is F? F.f?
Forget it. Do not waste your time with OCR.
Grab a map, what let you moving when shows you with a blue point middled arrow, like this:
https://www.curseforge.com/wow/addons/leatrix-maps-classic/screenshots

For example you are at 340 200, founded arrow Imagesearch, and want to run 200 530 Goldshire. Run a direction 1s and check image on map again. Use screen pixel positions, as coordinates..
we tried this addon and with pixel color it was hard to use , and movent looks like a robot.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 131 guests