Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Right Triangle Algorythms
#3
awesome work but hard to paste into QM so reformatted for QM Forum. S

Function RTC
Code:
Copy      Help
/Dialog_Editor

function# hDlg message wParam lParam
if(hDlg) goto messages

;BEGIN DIALOG
;1 "" 0x90C80AC8 0x0 0 0 188 158 "Right Triangle Calculator"
;3 Static 0x54000000 0x0 6 6 176 30 "Enter any two known values of a right triangle to calculate the other values automatically.  Press SOLVE to begin."
;4 Edit 0x54030080 0x200 72 44 96 13 ""
;5 Edit 0x54030080 0x200 72 62 96 12 ""
;6 Edit 0x54030080 0x200 72 80 96 12 ""
;7 Edit 0x54030080 0x200 72 98 96 12 ""
;9 Static 0x54000000 0x0 16 44 48 13 "Opposite Side"
;10 Static 0x54000000 0x0 16 62 48 12 "Adjacent Side"
;11 Static 0x54000000 0x0 16 80 48 12 "Hypotenuse"
;12 Static 0x54000000 0x0 16 98 48 12 "Angle A or B"
;14 ComboBox 0x54230243 0x0 72 116 96 213 "[]1[]2[]3[]4[]5[]Unlimited[]"
;15 Button 0x54032000 0x0 16 138 96 14 "SOLVE"
;16 Static 0x54000000 0x0 16 116 48 13 "Decimal Places[]"
;17 Button 0x54032000 0x0 120 138 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040202 "*" "" "" ""

;showdialog
str controls = "4 5 6 7 14"
str e4 e5 e6 e7 cb14
cb14 = "0[]1[]&2[]3[]4[]5[]Unlimited"
if(!ShowDialog("RTC" 0 &controls)) ret

goto beginmacro

;messages
sel message
,case WM_INITDIALOG DT_Init(hDlg lParam); ret 1
,case WM_DESTROY DT_DeleteData(hDlg)
,case WM_COMMAND goto messages2
ret
;messages2
ARRAY(str)- numbers
sel wParam
,case CBN_SELENDOK<<15|3
,_i=CB_SelectedItem(lParam)
,numbers[_i].setwintext(id(4 hDlg))
,
,case IDOK DT_Ok hDlg
,case IDCANCEL DT_Cancel hDlg
,case EN_CHANGE<<16|8
;;;
ret 1

;beginmacro

double Opp, Adj, Hyp, AngA, AngB  ;; This is where we get the results
double O, A, H, Aa, Ab, Ac, Tmp   ;; We'll use these for our temporary known values
def PI 3.1415926535897932384626433832795

O = val(e4)
A = val(e5)
H = val(e6)
Aa = val(e7)
int Rd = val(cb14)

if Aa = 0
,if O && A
,,Aa=atan(O/A)
,if A && H
,,Aa=acos(A/H)
,if H && O
,,Aa=asin(O/H)

Hyp = H
Opp = O
Adj = A
AngA = Aa
AngB = Ab

if Opp && Hyp
,AngA = asin(Opp/Hyp)*180/PI ;; use this if the Opp and Hyp are the only known dimensions
if Adj && Hyp
,AngA = acos(Adj/Hyp)*180/PI ;; Use this if the Adj and Hyp are the only known dimensions
if Opp && Adj
,AngA = atan(Opp/Adj)*180/PI ;; Use this if the App and Adj are the only known dimensions

if AngA == 0
,AngA = 90 - AngB
if AngB == 0
,AngB = 90 - AngA
;;;
if (AngB+AngA) == 0
,end

Aa = (AngA*PI)/180
Ab = (AngB*PI)/180

if Opp
,if Hyp == 0
,,A = sin(Aa)
,,Hyp = Opp/A
,if Adj == 0
,,A = tan(Aa)
,,Adj = Opp/A
if Adj
,if Hyp == 0
,,A = cos(Aa)
,,Hyp = Adj/A
,if Opp == 0
,,A = tan(Aa)
,,Opp = A*Adj
if Hyp
,if Adj == 0
,,A = cos(Aa)
,,Adj = A*Hyp
,if Opp == 0
,,A = sin(Aa)
,,Opp = A*Hyp

Opp  = Round(Opp Rd)
Adj  = Round(Adj Rd)
Hyp  = Round(Hyp Rd)
AngA = Round(AngA Rd)
AngB = Round(AngB Rd)

out "--------------------------------------------------"
out F"The Opposite   = {Opp}"
out F"The Adjacent   = {Adj}"
out F"The Hypotenuse = {Hyp}"
out F"The Angle A    = {AngA}"
out F"The Angle B    = {AngB}"

mes (F"The Opposite     : {Opp}[]The Adjacent     : {Adj}[]The Hypotenuse: {Hyp}[]The Angle A       : {AngA}[]The Angle B       : {AngB}")


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)