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")
}
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")
}
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")
}
Thxjeeswg wrote: .
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
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
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
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
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
}
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
Users browsing this forum: mikeyww and 318 guests