Determine Angles

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
V0RT3X
Posts: 366
Joined: 20 May 2023, 21:59
Contact:

Determine Angles

09 Jun 2024, 08:00

I haven't come across any scripts (yet) that can determine the angle between two points (mouse clicks).
The following are 2 scripts...
One to determine the angle off the x-axis and
One to determine the angle off the y-axis.
Hopefully they are helpful to someone.


X-Axis
X-Axis.png
X-Axis.png (5.04 KiB) Viewed 528 times
Spoiler

Y-Axis
Y-Axis.png
Y-Axis.png (5.51 KiB) Viewed 528 times
Spoiler
User avatar
andymbody
Posts: 1034
Joined: 02 Jul 2017, 23:47

Re: Determine Angles

09 Jun 2024, 12:26

Just a thought... might be worth combining the two scripts and providing a realtime graphical update of start position and current mouse position, maybe even a wedge/pie (partial circle) overlay, with angle detail updates as the mouse moves. Could also include x/y offset details. Just an idea.
User avatar
V0RT3X
Posts: 366
Joined: 20 May 2023, 21:59
Contact:

Re: Determine Angles

09 Jun 2024, 12:41

Ha...that would be a definite upgrade, but way above my skill grade. I'm lucky I managed these.
But I needed them for some graphics work I do. Please feel free to take this and run with it as you see fit.
User avatar
andymbody
Posts: 1034
Joined: 02 Jul 2017, 23:47

Re: Determine Angles

09 Jun 2024, 13:25

V0RT3X wrote:
09 Jun 2024, 12:41
Please feel free to take this and run with it as you see fit.
Ok... might do that at some point for the challenge. Will post it here if I do.
noticz
Posts: 3
Joined: 21 Oct 2014, 13:16

Re: Determine Angles

08 Nov 2024, 04:19

Any takers on making a GUI for this?
User avatar
Hellbent
Posts: 2288
Joined: 23 Sep 2017, 13:34

Re: Determine Angles

08 Nov 2024, 06:16

noticz wrote:
08 Nov 2024, 04:19
Any takers on making a GUI for this?
I'm not sure if this is what you had in mind or not but I made this a few years ago.

What you think is 90 is actually 270 due to the Y-axis flip for your monitor.
.
angle 1.gif
angle 1.gif (308.01 KiB) Viewed 108 times
.

Code: Select all

;***************************************************************************************************
#Include <GDIP_ALL> ;GDIP:  https://www.autohotkey.com/boards/viewtopic.php?f=6&t=6517
;***************************************************************************************************
#SingleInstance, Force
SetBatchLines, -1
CoordMode, Mouse, Client
GDIP_Startup()
global PicHwnd , Start := New HB_Vector( 100, 100 ) , End := New HB_Vector()
Gui, 1:+AlwaysOnTop -DPIScale +E0x02000000 +E0x00080000
Gui, 1:Color, 22262A
Gui, 1:Margin, 0, 0
Gui, 1:Add, Picture, xm ym w200 h250 0xE HwndPicHwnd
Gui, 1:Show,,Distance
CursorMove()
OnMessage(0x200,"CursorMove")
return
GuiClose:
GuiContextMenu:
*ESC::ExitApp
CursorMove(){
	MouseGetPos, x, y
	Angle := New HB_Vector( x - 100 , y - 100 )
	DrawGraphics( End.X := x , End.Y := y , Angle.GetAngle() )
	sleep, 10
}
Class HB_Vector	{
	static RadToDeg := 45 / ATan( 1 ) 
		, DegToRad := ATan( 1 ) / 45 
	__New(x:=0,y:=0){
		This.X:=x , This.Y:=y
	}dist(in1){
		return Sqrt(((This.X-In1.X)**2) + ((This.Y-In1.Y)**2))
	}
	GetAngle(){ 
		local angle 
		( (  angle := HB_Vector.RadToDeg * DllCall( "msvcrt\atan2" , "Double" , This.Y , "Double" , This.X , "CDECL Double" ) ) < 0 ) ? ( angle += 360 )
		return angle
	}
}
DrawGraphics(x,y,Angle){
	;Bitmap Created Using: HB Bitmap Maker
	pBitmap := Gdip_CreateBitmap( 200 , 250 ) , G := Gdip_GraphicsFromImage( pBitmap ) , Gdip_SetSmoothingMode( G , 4 )
	Pen := Gdip_CreatePen( "0xFF3399FF" , 1 ) , Gdip_DrawEllipse( G , Pen , 20 , 20 , 160 , 160 ) , Gdip_DeletePen( Pen )
	Pen := Gdip_CreatePen( "0xFFffff00" , 1 ) , Gdip_DrawEllipse( G , Pen ,  100 - distance , 100 - distance , distance*2 , distance * 2  ) , Gdip_DeletePen( Pen )
	Pen := Gdip_CreatePen( "0xFF880000" , 1 ) , Gdip_DrawLine( G , Pen , 99 , 10 , 99 , 190 ) , Gdip_DeletePen( Pen )
	Pen := Gdip_CreatePen( "0xFF33C833" , 1 ) , Gdip_DrawLine( G , Pen , 10 , 99 , 190 , 99 ) , Gdip_DeletePen( Pen )
	Pen := Gdip_CreatePen( "0xFFffff00" , 1 ) , Gdip_DrawLine( G , Pen , 99 , 100 , x , y ) , Gdip_DeletePen( Pen )
	Pen := Gdip_CreatePen( "0xFFff00ff" , 1 ) , Gdip_DrawRectangle( G , Pen , (x>=99)?(99):(x) , (y>=99)?(99):(y) , (x>=99)?(x-99):(99-x) , (y>=99)?(y-99):(99-y) ) , Gdip_DeletePen( Pen )
	Brush := Gdip_BrushCreateSolid( "0xFF3399FF" ) , Gdip_TextToGraphics( G , "Distance 80px" , "s12 Center vCenter Bold c" Brush " x0 y0" , "Segoe ui" , 200 , 17 ) , Gdip_DeleteBrush( Brush )
	Brush := Gdip_BrushCreateSolid( "0xFFFFFF00" ) , Gdip_TextToGraphics( G , "Angle: "  Angle , "s12 Center vCenter Bold c" Brush " x0 y220" , "Segoe ui" , 200 , 17 ) , Gdip_DeleteBrush( Brush )
	Gdip_DeleteGraphics( G ) , hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap) , Gdip_DisposeImage( pBitmap ) , SetImage( PicHwnd , hBitmap ) , DeleteObject( hBitmap )
}

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 47 guests