Calculate vertices of equilateral triangle Topic is solved

Talk about anything
jsbjsb12345
Posts: 14
Joined: 08 Jul 2020, 19:00

Calculate vertices of equilateral triangle

07 May 2022, 04:01

Hi everyone,

I'm stuck on something I have absolutely no clue about.
Given I have two coordinates of an equilateral triangle how do I calculate the third vertices in ahk.

I'll be honest I was watching YT tutorials and could barely wrap my head around the math so I have absolutely no code to post. :lol:

E.g. an equilateral triangle
Verticies cord point A is 2,3
Verticies cord point B is 6,6
Verticies cord point C is ?,?

I throw myself upon the mercy of the ahk-math gurus.

Ty
User avatar
mikeyww
Posts: 28871
Joined: 09 Sep 2014, 18:38

Re: Calculate vertices of equilateral triangle

07 May 2022, 05:39

Just my two cents, but I think that this question has nothing to do with AutoHotkey.
jsbjsb12345
Posts: 14
Joined: 08 Jul 2020, 19:00

Re: Calculate vertices of equilateral triangle

07 May 2022, 06:10

mikeyww wrote:
07 May 2022, 05:39
Just my two cents, but I think that this question has nothing to do with AutoHotkey.
I'm trying to write something in AHK that uses the calculation as part of it.
Searching for two locations on screen then calculating the 3rd location.
User avatar
boiler
Posts: 17706
Joined: 21 Dec 2014, 02:44

Re: Calculate vertices of equilateral triangle

07 May 2022, 06:27

I agree that the answer being sought is independent of the language. It’s really about the math, which once determined is trivial to actually code in AHK or any other language. Moving the thread to the “Offtopic” sub-forum.
User avatar
boiler
Posts: 17706
Joined: 21 Dec 2014, 02:44

Re: Calculate vertices of equilateral triangle

07 May 2022, 06:33

jsbjsb12345 wrote: I'm trying to write something in AHK that uses the calculation as part of it.
Searching for two locations on screen then calculating the 3rd location.
There was nothing asked about how to search locations on the screen. That would have been AHK-related. Either you already know how to do that or it wasn’t part of this request for help. It is purely about the math.
User avatar
boiler
Posts: 17706
Joined: 21 Dec 2014, 02:44

Re: Calculate vertices of equilateral triangle  Topic is solved

07 May 2022, 07:37

Having said that, here is the math demonstrated using AHK:

Code: Select all

; definition of two points of triangle:
x1 := 20, y1 := 30
x2 := 60, y2 := 60

; midpoint between points 1 and 2:
xMP := (x1 + x2) / 2
yMP := (y1 + y2) / 2

; slope of the line perpendicular to the first side of the triangle (inverse of its slope):
mP := (x2 - x1) / (y2 - y1)

; unit length vector along that slope:
rP := Sqrt(1 + mP**2)

; length of a side of the equilateral triangle:
dS := Sqrt((x2 - x1)**2 + (y2 - y1)**2)

; distance from the midpoint of first side of the triangle to point 3 of the triangle:
dMP3 := Sqrt(ds**2 - (ds / 2) ** 2)

; the first of two solutions:
x3_1 := xMP + dMP3 / Sqrt(1 + mP**2)
y3_1 := yMP - dMP3 * mP / Sqrt(1 + mP**2)

; the second of two solutions:
x3_2 := xMP - dMP3 / Sqrt(1 + mP**2)
y3_2 := yMP + dMP3 * mP / Sqrt(1 + mP**2)

Gui, +ToolWindow
Gui, Color, Black
Gui, Add, Progress, x%x1% y%y1% w2 h2 BackgroundWhite
Gui, Add, Progress, x%x2% y%y2% wp hp BackgroundWhite
Gui, Add, Progress, x%x3_1% y%y3_1% wp hp BackgroundRed
Gui, Add, Progress, x%x3_2% y%y3_2% wp hp BackgroundYellow
Gui, Show, w100 h100, Triangles
return

GuiClose:
ExitApp
jsbjsb12345
Posts: 14
Joined: 08 Jul 2020, 19:00

Re: Calculate vertices of equilateral triangle

07 May 2022, 21:36

Fair enough, thanks for the example boiler I'll give it a go when I get home!

Return to “Off-topic Discussion”

Who is online

Users browsing this forum: No registered users and 39 guests