Can anybody help?

i try

Code: Select all

```
ang:=atan2(aX-bX, aY- bY)
MsgBox % ang ;2.359474
atan2(x,y) { ; 4-quadrant atan
Return dllcall("msvcrt\atan2","Double",y, "Double",x, "CDECL Double")
}
```

Hi forum. How to find angle between two dots?

Can anybody help?

i try

but i get 2.359474 why not 45 ?

Can anybody help?

i try

Code: Select all

```
ang:=atan2(aX-bX, aY- bY)
MsgBox % ang ;2.359474
atan2(x,y) { ; 4-quadrant atan
Return dllcall("msvcrt\atan2","Double",y, "Double",x, "CDECL Double")
}
```

Angle = ArcTan(dy/dx)

to degrees: Angle = Angle*180/Pi

to degrees: Angle = Angle*180/Pi

Code: Select all

```
;tan x = opp / adj
;x = atan(opp / adj)
;https://autohotkey.com/docs/commands/Math.htm
;Note: To convert a radians value to degrees, multiply it by 180/pi (approximately 57.29578). To convert a degrees value to radians, multiply it by pi/180 (approximately 0.01745329252). The value of pi (approximately 3.141592653589793) is 4 times the arctangent of 1.
q:: ;calculate angle between 2 points
vAX := 0, vAY := 0
;vBX := 4, vBY := 5
vBX := 4, vBY := 4
MsgBox, % ATan((vBY-vAY)/(vBX-vAX))*57.29578 ;45.000000
MsgBox, % atan2(vBY-vAY, vBX-vAX) ;0.785398
MsgBox, % atan2(vBY-vAY, vBX-vAX)*57.29578 ;45.000000
return
atan2(x,y) { ; 4-quadrant atan
Return dllcall("msvcrt\atan2","Double",y, "Double",x, "CDECL Double")
}
```

If A is (0,0) and bX=bY, you would expect 0.785398 rad (45 deg) not 2.359474 rad (135.19 deg).

Thxjeeswg wrote: .

but now i have new problem

what i do wrong?

Code: Select all

```
SearchPointA()
SearchPointB()
SearchPointС()
angle := ATan((bX-aX)/(bY-aY))
length = 80
dX := cX + length * cos(angle)
dY := cY + length * sin(angle)
MouseMove % dX, % dY
ExitApp
```

oh it is work

but how to do right direction?

Btw, do check the order of ATan, it is normally y first, then x.

If other things don't work, you can always do something like:

If other things don't work, you can always do something like:

Code: Select all

```
vDirection := (vDest > vSource) ? 1 : -1
vOffset := Abs(vDistance) * vDirection
```

Thxjeeswg wrote:Btw, do check the order of ATan, it is normally y first, then x.

If other things don't work, you can always do something like:Code: Select all

`vDirection := (vDest > vSource) ? 1 : -1 vOffset := Abs(vDistance) * vDirection`

this work wevy good

Code: Select all

```
SearchPointA()
SearchPointB()
SearchPointС()
angle := ATan((bY-aY)/(bX-aX))
length = 180
dX := cX + length * cos(angle) * orderX := aX<bX ? 1: -1
dY := cY + length * sin(angle) *orderX := aX<bX ? 1: -1
MouseMove % dX, % dY
```

can u show me more clear code? or is this ok?

Anybody know hot to find the distance from point A to B

can anybody helm me with code?

distance := sqrt((y2-y1)**2+(X2-X1)**2)

is it right?

can anybody helm me with code?

distance := sqrt((y2-y1)**2+(X2-X1)**2)

is it right?

At the "Compass" link I posted above, search for the function "pxDist".

I'm not sure if years of maths study or years of programming will make some of these particular programming challenges any easier, the problem is simply that they are quite fiddly. I believe that my script below is right, all I can do is test it.

Part of the fiddliness is whether the vertical/horizontal distances will be positive/negative as required or whether you have to force it. There may be some trick I'm missing that would make this easier.

Another issue is whether an angle of 30 degrees or an angle of 60 degrees is wanted. Both are 30 degrees relative to either the x-axis or the y-axis.

Btw there is also this key issue to be aware of that I'd seen before but had since forgotten:
[EDIT:]

Related:

BITMAPINFOHEADER structure (Windows)

https://msdn.microsoft.com/en-us/librar ... s.85).aspx

Part of the fiddliness is whether the vertical/horizontal distances will be positive/negative as required or whether you have to force it. There may be some trick I'm missing that would make this easier.

Another issue is whether an angle of 30 degrees or an angle of 60 degrees is wanted. Both are 30 degrees relative to either the x-axis or the y-axis.

Code: Select all

```
q:: ;start at A (0,0), move 80 pixels in the direction of B
vAX := 0, vAY := 0
vBX := 1, vBY := 1
vAngle := ATan((vBY-vAY)/(vBX-vAX))
vAngleDeg := vAngle*57.29578
;Clipboard := vAngleDeg
;distance between 2 points:
;MsgBox, % Sqrt((vBX-vAX)**2+(vBY-vAY)**2)
; 1 1 44.999991
; 1 -1 -44.999991
;-1 1 -44.999991
;-1 -1 44.999991
; 2 1 26.565074
; 2 -1 -26.565074
;-2 1 -26.565074
;-2 -1 26.565074
;sin x = opp / hyp
;opp = sin x * hyp
;cos x = adj / hyp
;adj = cos x * hyp
vDist := 80
;vOffsetX := Cos(vAngle)*vDist
;vOffsetY := Sin(vAngle)*vDist
vOffsetX := Abs(Cos(vAngle)*vDist) * ((vBX > vAX) ? 1 : -1)
vOffsetY := Abs(Sin(vAngle)*vDist) * ((vBY > vAY) ? 1 : -1)
;Cartesian coordinates: y decreases as you go downwards
;screen coordinates: y increases as you go downwards
;thus -vOffsetY
;MsgBox, % vAngleDeg " " vOffsetX " " vOffsetY
MouseMove % vOffsetX, % -vOffsetY,, R
return
```

Code: Select all

```
;be aware of Cartesian coordinates: y decreases as you go downwards
; y
; |
;-x — + — x
; |
; -y
;v. screen coordinates: y increases as you go downwards
; + — x
; |
; y
```

Related:

BITMAPINFOHEADER structure (Windows)

https://msdn.microsoft.com/en-us/librar ... s.85).aspx

biHeight

The height of the bitmap, in pixels. If biHeight is positive, the bitmap is a bottom-up DIB and its origin is the lower-left corner. If biHeight is negative, the bitmap is a top-down DIB and its origin is the upper-left corner.

Code: Select all

```
MsgBox, % Angle(0, 1, 1, 0)
Angle(x1, y1, x2, y2) {
return ACos((x1 * x2 + y1 * y2) / (Sqrt(x1**2 + y1**2) * Sqrt(x2**2 + y2**2))) * 57.2957795
}
```

Please excuse my spelling I am dyslexic.

Just want to say THANK YOU! this is the only post online I could find about ATAN2 as it relates to Authotkey ! Coming from atan I had hax setup to detect if it was -135 or +135 (90 !?!?) and add or subtract 180 but it looks like this is exactly what I need for navigation!

The long way to do the math for using past (W*) and current (*A* cordraw) and coordinates to determine heading and corrections to destination Gx and Gy

https://stackoverflow.com/questions/283 ... atan2-in-c

The long way to do the math for using past (W*) and current (*A* cordraw) and coordinates to determine heading and corrections to destination Gx and Gy

https://stackoverflow.com/questions/283 ... atan2-in-c

Code: Select all

```
atan2(x,y) { ; 4-quadrant atan
Return dllcall("msvcrt\atan2","Double",y, "Double",x, "CDECL Double")
}
;note ATAN2 is all reversed Y then X ...
atan2_WAX:=xcordraw-WasX
atan2_WAY:=ycordraw-WasY
atan2_AGX:=Gx-xcordraw
atan2_AGY:=Gy-ycordraw
atan2_WAD:=atan2(atan2_WAY,atan2_WAX)
atan2_WAD:=(atan2_WAD*180)/3.14159265359
atan2_AGD:=atan2(atan2_AGY,atan2_AGX)
atan2_AGD:=(atan2_AGD*180)/3.14159265359
atan2_WAGC:=atan2_WAD-atan2_AGD
```