Recommended Posts

Here's my latest project, it's a small app that calculates sides/angles of a standard triangle.

I did this because I have just started studying trigonometry at school and thought it would be cool to do some real work with the Law of Sines and Law of Cosines.

The code turned out to be a lot harder than I thought and it ended up being a bit messy with loads of ifs, but it works so at least, mission accomplished Any suggestion how to shorten the code would be great, maybe an equation solver?

Ps. If you get -1.#IND it means you have entered a non-real triangle, it's not a bug Edited by monoceres

Broken link? PM me and I'll send you the file!

When I enter:

a=1

b=1

c=2

I get:

A=0

B=0

C=180

Expected:

A=45

B=45

C=90

Share on other sites

When I enter:

a=1

b=1

c=2

I get:

A=0

B=0

C=180

Expected:

A=45

B=45

C=90

I checked this in Microsoft Math, and it said c must be lesser than the sum of the other sides.

I have checked a great deal of values against microsoft math and they seem do be correct.

Broken link? PM me and I'll send you the file!

Share on other sites

I guess I do get the same result here:

http://www.trig.ionichost.com/trig.php

Also I didn't know I was supposed to click the triangle after entering my values, perhaps this should be indicated somehow?

Share on other sites

I guess I do get the same result here:

http://www.trig.ionichost.com/trig.php

Also I didn't know I was supposed to click the triangle after entering my values, perhaps this should be indicated somehow?

Didn't a little tooltip arise from the autoit tray icon?

But if you missed it, it's a sign it's not visible enough. Will add some visual info Broken link? PM me and I'll send you the file!

Share on other sites

Didn't a little tooltip arise from the autoit tray icon?

But if you missed it, it's a sign it's not visible enough. Will add some visual info You know what, it popped up but under all of my other windows.

Share on other sites

Uploaded updated script, now there should be no problems to finding that you need to click the triangle to solve it Broken link? PM me and I'll send you the file!

Share on other sites

When I enter:

a=1

b=1

c=2

I get:

A=0

B=0

C=180

Expected:

A=45

B=45

C=90

Oh man I just realized why this is wrong...I was not thinking at all. This would in effect make a straight line. Share on other sites

Oh man I just realized why this is wrong...I was not thinking at all. This would in effect make a straight line. Which make my script right That's why I love math formulas, they never turn out wrong, even when you try to f with them.

Broken link? PM me and I'll send you the file!

Share on other sites

The sides can't be floats?

(ex: 3.2 units) My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share on other sites

The sides can't be floats?

(ex: 3.2 units)

It's the damn \$ES_NUMBER style... I upload one without it. (Who is stupid enough to write text into a triangle solver anyway?).

Broken link? PM me and I'll send you the file!

Share on other sites

Edit:

something is still wrong

a=1 A=30

b=2 B=60

c=? C=90

Returns

a=1 A=30

b=1.73205080756888 B=60

c=2 C=90

Where it should return

a=1 A=30

b=2 B=60

c=2.23606... C=90

Edit: I mean, it's correct - but it shouldn't be changing fields I inputted manually... because sides (1,2,?) and angles (30,60,90) are possible if c is 2.23606...

As I defined it already as a right-triangle with correct angles and sides, we should be able to use:

Sqrt((1^2)+(2^2))=2.23606797749979

Edited by crashdemons My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share on other sites

Sorry if I sounded like I was trashing your script - I really like it, I just have a few things that bug me about it. My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share on other sites

It's the damn \$ES_NUMBER style... I upload one without it. (Who is stupid enough to write text into a triangle solver anyway?).

StringisDigit()

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share on other sites

Thx for the input, really I appreciate it. It just that the code is not very well written so I just don't think I will update it in the near future.

Actually I rather rewrite the whole solving function than begin editing it.

Edited by monoceres

Broken link? PM me and I'll send you the file!

Share on other sites

Thx for the input, really I appreciate it. It just that the code is not very well written so I just don't think I will update it in the near future.

Actually I rather rewrite the whole solving function that begin editing it.

Interesting. This could be useful. You should make it work backwards too. For example, if they fill in the angles of the triangle, it should return the length of the sides. Share on other sites

Right!! I know this is old, but i needed this for h/w, and It looks fun!

Done a bit of work, and made it a bit better with another theorem used - pythagoras' a^2 + b^2 = c^2. Now if you input no angles, but 2 sides, it will presume angle C is 90 and work it out.

I also changed most of the variables and re did the help bit (The tray icon tip was pssing me off).

I like this idea so i'm going to completely re do it soon, so the inputs are actually on the triangle. (need to have a look at GDI though, i haven't done that before)

The updated code:

CODE

; Triangle solver, solves every solveable standard triangle ;---------------------------------------------------------------------

;

; Author: monoceres

; Thanks to: eviltoaster, weaponx and The Kandie Man for help about degrees and radians

;

;---------------------------------------------------------------------------------------------------------------------------------

;

; Triangle laws used:

; * Law of Cosines: a^2=b^2+c^2 -2bcCos(A)

; * Law of Sines: a/Sin(A) = b/Sin( = c/Sin©

; * A+B+C = 180

;

; Edit by MDiesel: ;--------------------------------------------------------------------------------------------------------------

;

; New triangle laws:

; * a^2 + b^2 = c^2

;

; Other edits:

; Renamed variables and tried to neaten it up... it needed a bit more consistency - he sometimes uses a space, he sometimes

; doesn't, and it annoys OCD people like me.

;

;---------------------------------------------------------------------------------------------------------------------------------

; Includes, beta safe!

#include <Math.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#include <StaticConstants.au3>

#include <EditConstants.au3>

#include <Misc.au3>

Opt ("GUIOnEventMode", 1)

Opt ("MouseCoordMode", 2)

#NoTrayIcon

\$hGUI = GUICreate ("Triangle Solver", 501, 339, -1, -1)

GUICtrlCreateLabel ("Left click the triangle to solve it. Right click to reset all fields.", 0, 0, 300, 20) ; Replaced the help tooltip

GUICtrlSetOnEvent (-1, "Help")

\$Triangle_Pic = GUICtrlCreatePic (@ScriptDir & "\triangle.gif", 8, 20, 480, 180, BitOR (\$SS_NOTIFY, \$WS_GROUP, \$WS_CLIPSIBLINGS))

GUICtrlSetOnEvent (\$Triangle_Pic, "_ProcessTriangle")

\$gSides = GUICtrlCreateGroup ("Sides", 8, 200, 237, 113)

GUICtrlCreateLabel ("a", 24, 216, 10, 17)

\$sA_Inp = GUICtrlCreateInput ("", 48, 216, 121, 21)

GUICtrlCreateLabel ("b", 24, 248, 10, 17)

\$sB_Inp = GUICtrlCreateInput ("", 48, 248, 121, 21)

GUICtrlCreateLabel ("c", 24, 280, 10, 17)

\$sc_Inp = GUICtrlCreateInput ("", 48, 280, 121, 21)

\$gAngles = GUICtrlCreateGroup ("Angles", 256, 200, 237, 113)

GUICtrlCreateLabel ("A", 272, 216, 11, 17)

\$aA_Inp = GUICtrlCreateInput ("", 296, 216, 121, 21)

GUICtrlCreateLabel ("B", 272, 248, 11, 17)

\$aB_Inp = GUICtrlCreateInput ("", 296, 248, 121, 21)

GUICtrlCreateLabel ("C", 272, 280, 11, 17)

\$aC_Inp = GUICtrlCreateInput ("", 296, 280, 121, 21)

GUISetOnEvent (-3, "close")

GUISetState (@SW_SHOW)

;TrayTip ("Tip", "Left click the triangle to solve it." & @CRLF & "Right click to reset all fields.", 8)

While 1

Sleep(100)

If _IsPressed("02") Then ; Reset fields if mouse button 2 is pressed on triangle.

\$mouse = MouseGetPos()

If \$mouse >= 8 And \$mouse <= 488 And \$mouse >= 8 And \$mouse <= 188 Then

GUICtrlSetData(\$sA_Inp, "")

GUICtrlSetData(\$sB_Inp, "")

GUICtrlSetData(\$sc_Inp, "")

GUICtrlSetData(\$aA_Inp, "")

GUICtrlSetData(\$aB_Inp, "")

GUICtrlSetData(\$aC_Inp, "")

Sleep(500)

EndIf

EndIf

WEnd

Func _ProcessTriangle()

Local \$ifsum, \$ifsum2, \$bool = False

If StringRight (\$aA, 1) = Chr (176) Then \$aA = StringTrimRight (\$aA, 1)

If StringRight (\$aB, 1) = Chr (176) Then \$aB = StringTrimRight (\$aB, 1)

If StringRight (\$aC, 1) = Chr (176) Then \$aC = StringTrimRight (\$aC, 1)

; Info is gathered to see how many things are known

If \$aA <> "" Then \$ifsum += 1

If \$aB <> "" Then \$ifsum += 1

If \$aC <> "" Then \$ifsum += 1

If \$sA <> "" Then \$ifsum2 += 1

If \$sB <> "" Then \$ifsum2 += 1

If \$sC <> "" Then \$ifsum2 += 1

If (\$ifsum < 2 And \$ifsum2 < 2) Or \$ifsum2 < 1 Then ; 1 angle + 2 sides or 2 angles + 1 side is required to solve triangle

MsgBox(16, "Error", "Not enough information entered to solve this triangle")

Return 0

EndIf

If \$ifsum = 2 And \$aA + \$aC + \$aB < 180 Then

If \$aA = "" Then

\$aA = 180 - \$aB - \$aC

ElseIf \$aB = "" Then

\$aB = 180 - \$aA - \$aC

Else

\$aC = 180 - \$aA - \$aB

EndIf

\$ifsum += 1

EndIf

If (\$aA + \$aB + \$aC > 180) Or (\$ifsum = 3 And \$aA + \$aB + \$aC < 180) Then ; User tried inputting invalid triangle (Angles not add up to 180)

MsgBox(16, "Triangle error", "Total sum of the angles must be 180°")

Return 0

EndIf

If \$sA <> "" And \$sB <> "" And \$sC <> "" Then ; If all sides are know, lets calculate angles

\$aA = Round(_Degree(ACos((\$sB ^ 2 + \$sC ^ 2 - \$sA ^ 2) / (2 * \$sC * \$sB))), 2) ; Law of Cosines

\$aB = Round(_Degree(ACos((\$sA ^ 2 + \$sC ^ 2 - \$sB ^ 2) / (2 * \$sC * \$sA))), 2) ; Law of Cosines

\$aC = 180 - \$aB - \$aA

ElseIf \$ifsum > 1 Then ; If we know more than one angle

If \$sA <> "" Then

ElseIf \$sB <> "" Then

ElseIf \$sC <> "" Then

EndIf

ElseIf \$ifsum2 > 1 Then ; We know more than one side

If \$sA <> "" And \$aA <> "" Then

If \$sB <> "" Then

\$aB = _Degree(ASin(\$sB / (\$sA / Sin(_Radian(\$aA))))) ; Law of Sines

\$aC = 180 - \$aB - \$aA

ElseIf \$sC <> "" Then

\$aB = _Degree(ASin(\$sC / (\$sA / Sin(_Radian(\$aA))))) ; Law of Sines

\$aB = 180 - \$aC - \$aA

EndIf

ElseIf \$sC <> "" And \$aC <> "" Then

If \$sB <> "" Then

\$aB = _Degree(ASin(\$sB / (\$sC / Sin(_Radian(\$aC))))) ; Law of Sines

\$aA = 180 - \$aB - \$aC

ElseIf \$sA <> "" Then

\$aA = _Degree(ASin(\$sA / (\$sC / Sin(_Radian(\$aC))))) ; Law of Sines

\$aB = 180 - \$aA - \$aC

EndIf

ElseIf \$sB <> "" And \$aB <> "" Then

If \$sA <> "" Then

\$aA = _Degree(ASin(\$sA / (\$sB / Sin(_Radian(\$aB))))) ; Law of Sines

\$aC = 180 - \$aB - \$aA

ElseIf \$sC <> "" Then

\$aC = _Degree(ASin(\$sC / (\$sB / Sin(_Radian(\$aB))))) ; Law of Sines

\$aA = 180 - \$aB - \$aC

EndIf

Else ; No angle and side match, have to do some extra work

If \$aA = "" And \$aB = "" And \$aC = "" Then ; No angles given!!

\$aC = 90 ; presumes its right angled.

If \$sA <> "" And \$sB <> "" Then ; Find side c

\$sC = Sqrt ((\$sA ^ 2) + (\$sB ^ 2))

ElseIf \$sA <> "" And \$sC <> "" Then ; find b

\$sB = Sqrt ((\$sC ^ 2) - (\$sA ^ 2))

ElseIf \$sB <> "" And \$sC <> "" Then ; find a

\$sA = Sqrt ((\$sC ^ 2) - (\$sB ^ 2))

EndIf

EndIf

If \$sA = "" Then

\$sA = Sqrt (-2 * \$sB * \$sC * Cos (_Radian(\$aA)) + \$sB ^ 2 + \$sC ^ 2) ; Law of Cosines

ElseIf \$sB = "" Then

\$sB = Sqrt (-2 * \$sA * \$sC * Cos (_Radian(\$aB)) + \$sA ^ 2 + \$sC ^ 2) ; Law of Cosines

ElseIf \$sC = "" Then

\$sC = Sqrt (-2 * \$sA * \$sB * Cos (_Radian(\$aC)) + \$sA ^ 2 + \$sB ^ 2) ; Law of Cosines

EndIf

\$aA = Round (_Degree (ACos ((\$sB ^ 2 + \$sC ^ 2 - \$sA ^ 2) / (2 * \$sC * \$sB))), 2) ; Law of Cosines

\$aB = Round (_Degree (ACos ((\$sA ^ 2 + \$sC ^ 2 - \$sB ^ 2) / (2 * \$sC * \$sA))), 2) ; Law of Cosines

\$aC = 180 - \$aB - \$aA

EndIf

EndIf

; Set calculated values!

GUICtrlSetData (\$sA_Inp, \$sA)

GUICtrlSetData (\$sB_Inp, \$sB)

GUICtrlSetData (\$sc_Inp, \$sC)

GUICtrlSetData (\$aA_Inp, \$aA & Chr (176))

GUICtrlSetData (\$aB_Inp, \$aB & Chr (176))

GUICtrlSetData (\$aC_Inp, \$aC & Chr (176))

EndFunc ; ==> _ProcessTriangle

Func Close ()

Exit

EndFunc ; ==> close

Func Help ()

MsgBox (64,"Help for Triangle Solver","Left click the triangle when you have entered desired values to solve it." & @CRLF & _

"Right click it to reset all fields" & @CRLF & "The program will not warn you for everything, remember for example " & _

"that one side cannot be greater than the sum of the others. If you are really struggling then consider searching " & _

"the internet to see what the answer should be. If it is definitely a fault with the script then please report a bug.")

EndFunc ; ==> Help

MDiesel

oh and... @cppman:

and how do you suppose its possible to do that? you need to know at least 1 side to return an exact side. you can only get relatives.

edit:

ah: stoopid smileys. ruining my script! - Thanks res, but what happens if I want to use smileys as well? Edited by mdiesel

Share on other sites

Edit:

something is still wrong

a=1 A=30

b=2 B=60

c=? C=90

Returns

a=1 A=30

b=1.73205080756888 B=60

c=2 C=90

Where it should return

a=1 A=30

b=2 B=60

c=2.23606... C=90

Edit: I mean, it's correct - but it shouldn't be changing fields I inputted manually... because sides (1,2,?) and angles (30,60,90) are possible if c is 2.23606...

As I defined it already as a right-triangle with correct angles and sides, we should be able to use:

Sqrt((1^2)+(2^2))=2.23606797749979

Fixed

```; Triangle solver, solves every solveable standard triangle
; Author: monoceres
; Thanks to: eviltoaster, weaponx and The Kandie Man for help about degrees and radians

; Triangle laws I used::
; Law of Cosines: a^2=b^2+c^2 -2bcCos(A)
; Law of Sines: a/Sin(A) = b/Sin(B) = c/Sin©
; A+B+C = 180

; Includes, beta safe!
#include <Math.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <Misc.au3>

Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode", 2)
\$Form1 = GUICreate("Triangle Solver", 501, 339, -1, -1)
GUICtrlSetOnEvent(-1,"help")
\$Pic1 = GUICtrlCreatePic("triangle.gif", 8, 8, 480, 180, BitOR(\$SS_NOTIFY, \$WS_GROUP, \$WS_CLIPSIBLINGS))
GUICtrlSetOnEvent(-1, "_ProcessTriangle")
\$Group1 = GUICtrlCreateGroup("Sides", 8, 200, 237, 113)
\$Label1 = GUICtrlCreateLabel("a", 24, 216, 10, 17)
\$cla = GUICtrlCreateInput("", 48, 216, 121, 21)
\$Label2 = GUICtrlCreateLabel("b", 24, 248, 10, 17)
\$clb = GUICtrlCreateInput("", 48, 248, 121, 21)
\$Label3 = GUICtrlCreateLabel("c", 24, 280, 10, 17)
\$clc = GUICtrlCreateInput("", 48, 280, 121, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
\$Group2 = GUICtrlCreateGroup("Angles", 256, 200, 237, 113)
\$Label4 = GUICtrlCreateLabel("A", 272, 216, 11, 17)
\$Label5 = GUICtrlCreateLabel("B", 272, 248, 11, 17)
\$Label6 = GUICtrlCreateLabel("C", 272, 280, 11, 17)
\$cl_a = GUICtrlCreateInput("", 296, 216, 121, 21)
\$cl_b = GUICtrlCreateInput("", 296, 248, 121, 21)
\$cl_c = GUICtrlCreateInput("", 296, 280, 121, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetOnEvent(-3, "close")
GUISetState(@SW_SHOW)
TrayTip("Tip", "Left click the triangle to solve it." & @CRLF & "Right click to reset all fields.", 8)

While 1
Sleep(100)
If _IsPressed("02") Then ; Reset fields if mouse button 2 is pressed
\$mouse = MouseGetPos()
If \$mouse >= 8 And \$mouse <= 488 And \$mouse >= 8 And \$mouse <= 188 Then
GUICtrlSetData(\$cla, "")
GUICtrlSetData(\$clb, "")
GUICtrlSetData(\$clc, "")
GUICtrlSetData(\$cl_a, "")
GUICtrlSetData(\$cl_b, "")
GUICtrlSetData(\$cl_c, "")
Sleep(500)
EndIf
EndIf
WEnd

Func _ProcessTriangle()
Local \$ifsum, \$ifsum2, \$bool = False
If StringRight(\$aangle,1)=Chr(176) Then \$aangle=StringTrimRight(\$aangle,1)
If StringRight(\$bangle,1)=Chr(176) Then \$bangle=StringTrimRight(\$bangle,1)
If StringRight(\$cangle,1)=Chr(176) Then \$cangle=StringTrimRight(\$cangle,1)
; Info is gathered to see how many things are known
If \$aangle <> "" Then \$ifsum += 1
If \$bangle <> "" Then \$ifsum += 1
If \$cangle <> "" Then \$ifsum += 1
If \$sidea <> "" Then \$ifsum2 += 1
If \$sideb <> "" Then \$ifsum2 += 1
If \$sidec <> "" Then \$ifsum2 += 1

If (\$ifsum < 2 And \$ifsum2 < 2) Or \$ifsum2 < 1 Then ; 1 angle + 2 sides or 2 angles + 1 side is required to solve triangle or all sides
MsgBox(16, "Error", "Not enough information entered to solve this triangle")
Return
EndIf
If \$ifsum = 2 And \$aangle + \$cangle + \$bangle < 180 Then
If \$aangle = "" Then
\$aangle = 180 - \$bangle - \$cangle
ElseIf \$bangle = "" Then
\$bangle = 180 - \$aangle - \$cangle
Else
\$cangle = 180 - \$aangle - \$bangle
EndIf
\$ifsum += 1
EndIf
If (\$aangle + \$bangle + \$cangle > 180) Or (\$ifsum = 3 And \$aangle + \$bangle + \$cangle < 180) Then ; User tried inputting invalid triangle (Angles not add up to 180)
MsgBox(16, "Triangle error", "Total sum of the angles must be 180°")
Return
EndIf
If \$sidea <> "" And \$sideb <> "" And \$sidec <> "" And \$ifsum <> 3 Then ; If all sides are know, lets calculate angles
MsgBox(0, "", "2")
\$aangle = Round(_Degree(ACos((\$sideb ^ 2 + \$sidec ^ 2 - \$sidea ^ 2) / (2 * \$sidec * \$sideb))), 2) ; Law of Cosines
\$bangle = Round(_Degree(ACos((\$sidea ^ 2 + \$sidec ^ 2 - \$sideb ^ 2) / (2 * \$sidec * \$sidea))), 2) ; Law of Cosines
\$cangle = 180 - \$bangle - \$aangle
ElseIf \$ifsum > 1 and \$ifsum2 = 1 Then ; If we know more than one angle
MsgBox(0, "", "1")
If \$sidea <> "" Then
ElseIf \$sideb <> "" Then
ElseIf \$sidec <> "" Then
EndIf
ElseIf \$ifsum2 = 2 and \$ifsum <> 3 Then ; We know more than one side
If \$sidea <> "" And \$aangle <> "" Then
If \$sideb <> "" Then
\$bangle = _Degree(ASin(\$sideb / (\$sidea / Sin(_Radian(\$aangle))))) ; Law of Sines
\$cangle = 180 - \$bangle - \$aangle
ElseIf \$sidec <> "" Then
\$bangle = _Degree(ASin(\$sidec / (\$sidea / Sin(_Radian(\$aangle))))) ; Law of Sines
\$bangle = 180 - \$cangle - \$aangle
EndIf
ElseIf \$sidec <> "" And \$cangle <> "" Then
If \$sideb <> "" Then
\$bangle = _Degree(ASin(\$sideb / (\$sidec / Sin(_Radian(\$cangle))))) ; Law of Sines
\$aangle = 180 - \$bangle - \$cangle

ElseIf \$sidea <> "" Then
\$aangle = _Degree(ASin(\$sidea / (\$sidec / Sin(_Radian(\$cangle))))) ; Law of Sines
\$bangle = 180 - \$aangle - \$cangle

EndIf
ElseIf \$sideb <> "" And \$bangle <> "" Then
If \$sidea <> "" Then
\$aangle = _Degree(ASin(\$sidea / (\$sideb / Sin(_Radian(\$bangle))))) ; Law of Sines
\$cangle = 180 - \$bangle - \$aangle

ElseIf \$sidec <> "" Then
\$cangle = _Degree(ASin(\$sidec / (\$sideb / Sin(_Radian(\$bangle))))) ; Law of Sines
\$aangle = 180 - \$bangle - \$cangle
EndIf
Else ; No angle and side match, have to do some extra work
If \$sidea = "" Then
\$sidea = Sqrt(-2 * \$sideb * \$sidec * Cos(_Radian(\$aangle)) + \$sideb ^ 2 + \$sidec ^ 2) ; Law of Cosines
ElseIf \$sideb = "" Then
\$sideb = Sqrt(-2 * \$sidea * \$sidec * Cos(_Radian(\$bangle)) + \$sidea ^ 2 + \$sidec ^ 2) ; Law of Cosines
ElseIf \$sidec = "" Then
\$sidec = Sqrt(-2 * \$sidea * \$sideb * Cos(_Radian(\$cangle)) + \$sidea ^ 2 + \$sideb ^ 2) ; Law of Cosines
EndIf
\$aangle = Round(_Degree(ACos((\$sideb ^ 2 + \$sidec ^ 2 - \$sidea ^ 2) / (2 * \$sidec * \$sideb))), 2) ; Law of Cosines
\$bangle = Round(_Degree(ACos((\$sidea ^ 2 + \$sidec ^ 2 - \$sideb ^ 2) / (2 * \$sidec * \$sidea))), 2) ; Law of Cosines
\$cangle = 180 - \$bangle - \$aangle
EndIf
Else ;triangle is over defined
If \$sidea = "" Then \$sidea = Sqrt(-2 * \$sideb * \$sidec * Cos(_Radian(\$aangle)) + \$sideb ^ 2 + \$sidec ^ 2) ; Law of Cosines
If \$sideb = "" Then \$sideb = Sqrt(-2 * \$sidea * \$sidec * Cos(_Radian(\$bangle)) + \$sidea ^ 2 + \$sidec ^ 2) ; Law of Cosines
If \$sidec = "" Then \$sidec = Sqrt(-2 * \$sidea * \$sideb * Cos(_Radian(\$cangle)) + \$sidea ^ 2 + \$sideb ^ 2) ; Law of Cosines
If \$aangle = "" AND \$bangle <> "" AND \$cangle <> "" Then \$aangle = 180-\$bangle-\$cangle
If \$aangle <> "" AND \$bangle = "" AND \$cangle <> "" Then \$bangle = 180-\$aangle-\$cangle
If \$aangle <> "" AND \$bangle <> "" AND \$cangle = "" Then \$cangle = 180-\$aangle-\$bangle
EndIf
; Set calculated values!
GUICtrlSetData(\$cla, \$sidea)
GUICtrlSetData(\$clb, \$sideb)
GUICtrlSetData(\$clc, \$sidec)
GUICtrlSetData(\$cl_a, \$aangle&Chr(176))
GUICtrlSetData(\$cl_b, \$bangle&Chr(176))
GUICtrlSetData(\$cl_c, \$cangle&Chr(176))

EndFunc   ;==>_ProcessTriangle

Func close()
Exit
EndFunc   ;==>close

Func help()
MsgBox(64,"Help for Triangle Solver","Left click the triangle when you have entered desired values to solve it."&@CRLF&"Right click it to reset all fields"&@CRLF&"The program will not warn you for everything, remember for example that one side cannot be greater than the sum of the others")
EndFunc```

I don't have the code that assumes 90 deg in here and there seems to be some rounding error problems but this should work with any solvable triangle.

Edited by smstroble

MUHAHAHAHAHA