Jump to content

need help with cos,sin and tan


Alek
 Share

Recommended Posts

how do i use them with autoit.

what we have in school was to calculate the degree of one of the corners when one of degrees are 90* and we know the lenght of the side's

the problem is that i cant get the right number's of degree's in the corner i tryed to find.

#include <GUIConstants.au3>

$pi = 3.14159265358979
$radToDeg = 180 / $pi

$Form1 = GUICreate("", 390, 300, 193, 115)
$Input5 = GUICtrlCreateInput("hyp",150,80,50)
$Input6 = GUICtrlCreateInput("1",315,130,50)
$Input7 = GUICtrlCreateInput("2",150,210,50)
$Input9 = GUICtrlCreateInput("Degree",100,170,50)
$Button3 =  GUICtrlCreateButton("calculate", 280, 270, 80, 20)
$box1gui = GUICreate("", 320,280,20,-20,$WS_POPUP,BitOr($WS_EX_LAYERED,$WS_EX_MDICHILD),$Form1)
GUICtrlCreatePic("triangle.gif",0,0,320,280)

GUISetState(@SW_SHOW,$Form1)
GUISetState(@SW_SHOW,$box1gui)
Do
    $nmsg = GUIGetMsg()
    if $nmsg = $Button3 then calculate()
until $nmsg = $GUI_EVENT_CLOSE

func calculate()
    $hyp = guictrlread($Input5)
    $1 = guictrlread($Input6)
    $2 = guictrlread($Input7)
    if $1 = "" Then
        GUICtrlSetData($Input9,ACos($2/$hyp)*$radToDeg)
    EndIf
EndFunc

post-21482-1176390202_thumb.gif

really need some help with this, normaly when i use my calculator i just hit cos($1/$hyp) or cos-1($1/$hyp) cant remember :shocked:

PS:

whould also like to know how i could calculate the lenght of one of the side's when i know the degree's and one of the other side's

i hate this kind of math

sry for if you cant understand what im asking for.

[font="Impact"]Never fear, I is here.[/font]

Link to comment
Share on other sites

Only syntax correction, no math logic added:

func calculate()
    $hyp = guictrlread($Input5)
    $1 = guictrlread($Input6)
    $2 = guictrlread($Input7)
;~     if $1 = "" Then
        GUICtrlSetData($Input9,Round(ACos($2/$hyp)*$radToDeg,3))
;~     EndIf
EndFunc

So now it's generating some numbers ...

Link to comment
Share on other sites

This is the basic idea, but careful because I haven't checked it which means there are probably mistakes.

#include <GUIConstants.au3>

$pi = 3.14159265358979
$radToDeg = 180 / $pi

$Form1 = GUICreate("", 390, 300, 193, 115)
$Input5 = GUICtrlCreateInput("hyp",150,80,50)
$Input6 = GUICtrlCreateInput("1",315,130,50)
$Input7 = GUICtrlCreateInput("2",150,210,50)
$Input9 = GUICtrlCreateInput("Degree",100,170,50)
$Button3 =  GUICtrlCreateButton("calculate", 280, 270, 80, 20)
$box1gui = GUICreate("", 320,280,20,-20,$WS_POPUP,BitOr($WS_EX_LAYERED,$WS_EX_MDICHILD),$Form1)
GUICtrlCreatePic("triangle.gif",0,0,320,280)

GUISetState(@SW_SHOW,$Form1)
GUISetState(@SW_SHOW,$box1gui)
Do
    $nmsg = GUIGetMsg()
    if $nmsg = $Button3 then calculate()
until $nmsg = $GUI_EVENT_CLOSE

func calculate()
    $hyp = Execute(guictrlread($Input5))
    $1 = Execute(guictrlread($Input6))
    $2 = Execute(guictrlread($Input7))
    $a = Execute(guictrlread($Input9))
    
    if $a = '' Then
        if $1 <> '' and $2 <> '' Then
            GUICtrlSetData($Input9,stringformat('%.2f',ATan($1/$2)*$radToDeg))
            
        Elseif $1 <> '' and $hyp <> '' Then
            GUICtrlSetData($Input9,stringformat('%.2f',ASin($1/$hyp)*$radToDeg))
            
        elseif $2 <>'' and $hyp <> '' Then
            GUICtrlSetData($Input9,stringformat('%.2f',ACos($2/$hyp)*$radToDeg))
            
        EndIf
        


        
    Else
        if $1 = '' and $hyp <> '' Then
            GUICtrlSetData($Input6,stringformat('%.2f',Sin($a/$radToDeg) * $hyp))
            
        Elseif $2 = "" and $hyp <> '' Then
            GUICtrlSetData($Input7,stringformat('%.2f',Cos($a/$radToDeg)*$hyp))
            
        Elseif $hyp = '' and $1 <> ''  Then
            GUICtrlSetData($Input5,stringformat('%.2f',$1/Sin($a/$radToDeg)))
            
        ElseIf $hyp = '' and $2 <> '' Then
            GUICtrlSetData($Input5,stringformat('%.2f',$2/Cos($a/$radToDeg)))
        EndIf
    EndIf
    
EndFunc
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

PS:

whould also like to know how i could calculate the lenght of one of the side's when i know the degree's and one of the other side's

i hate this kind of math

sry for if you cant understand what im asking for.

sin theta = opposite / hypotenuse

cos theta = adjacent / hypotenuse

tan theta = opposite / adjacent

Say you have a 30 degree angle and opposite side length is 3 and you want to know the length of the adjacent side (bottom).

Use t for tangent of 30 degrees since tan = opp/adj a relationship of the sides in which we are interested.

t = 3/x

xt = 3

x = 3/t

since tan of 30 degrees = .577

x = 3 / 0.577

x = 5.19

~~~~~~~~~~~~~~

$pi = 3.14159265

$d2R = $pi / 180 ;degrees to radians since tan function use rads instead of degrees

$angle = 30

$opp = 3

$adjacent = $opp/(tan ($angle * $d2R))

MsgBox(0,"", $adjacent)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...