Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Angle of a line...
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Homer_simpson




PostPosted: Tue Jul 01, 2003 5:24 pm   Post subject: Angle of a line...

how do i calculate angle A knowing that line1 is always horizontal and having the coordinates of line2...
i know it has to be done using Sine and Cosine but i dont exactly know how....
Posted Image, might have been reduced in size. Click Image to view fullscreen.

Haven't had math in while so i've forgotten a few stuff... =/



math.JPG
 Description:
 Filesize:  7.86 KB
 Viewed:  10136 Time(s)

math.JPG


Sponsor
Sponsor
Sponsor
sponsor
Catalyst




PostPosted: Tue Jul 01, 2003 5:40 pm   Post subject: (No subject)

SOH CAH TOA

sin=op/hyp

your hyp is the distance from point1 to point2
since line 2 is always horizontal that distance is y2-y1

angle=sin-1((y2-y1)/distance (p1,p2))
Andy




PostPosted: Tue Jul 01, 2003 5:40 pm   Post subject: (No subject)

since tan of an angle is the oposite side over the adjancent side, you simply set up an equation of tan(x)=10/20 tan(x)=1/2 then u juss do tan inverse and you get 45 degrees
SilverSprite




PostPosted: Tue Jul 01, 2003 6:07 pm   Post subject: (No subject)

yepyep just something to add.. since tan is opposite side over adjacent side.. that means that it is simply the slope of the line meaning that tanA where A is the required angle is equal to the slope of the line.. so A = arctand(slope of line)
Homer_simpson




PostPosted: Tue Jul 01, 2003 6:44 pm   Post subject: (No subject)

hmmm.... got it!!! thx...
here's another question how do i caculate tangent (a) in Turing?
Andy




PostPosted: Tue Jul 01, 2003 6:53 pm   Post subject: (No subject)

there is no tangent in turing, but since tan(A)=sin(A)/cos(A) just substitute it
Homer_simpson




PostPosted: Tue Jul 01, 2003 6:58 pm   Post subject: (No subject)

no it's not i thought of that and i tried it b4 it doesn't work !!! =(
Edit:oh wait nvm i used cos instead of cosd now it works...

code:
function tan (r : real) : real
    result (sind (r) / cosd (r))
end tan

put tan (1)


how do i do arctan or sine-1? **-1 doesn't work =/
AsianSensation




PostPosted: Tue Jul 01, 2003 8:52 pm   Post subject: (No subject)

funny thing is, the geniuses who made turing(tom) decided not to put a inverse cos and sin function, said it was irrelevant.

so the best bet for using inverse tan is to make one urself....
Sponsor
Sponsor
Sponsor
sponsor
Catalyst




PostPosted: Tue Jul 01, 2003 9:09 pm   Post subject: (No subject)

such an old post (this is also in the help file)

http://www.compsci.ca/bbs/viewtopic.php?t=263&highlight=inverse
AsianSensation




PostPosted: Tue Jul 01, 2003 9:19 pm   Post subject: (No subject)

*stick foot in mouth

whoa, they had an arctan function? damn.......Im ignorant.......
Andy




PostPosted: Tue Jul 01, 2003 9:43 pm   Post subject: (No subject)

wow that's really cool... make ur own inverse functions
SilverSprite




PostPosted: Tue Jul 01, 2003 11:46 pm   Post subject: (No subject)

its math dodge.. you go to massey you should undetrstand those..
Homer_simpson




PostPosted: Wed Jul 02, 2003 12:00 am   Post subject: (No subject)

i didn't know they had arctan tangent in turing either... in fact that was all that i needed...
so here's how it goes:
code:
View.Set ("offscreenonly")

var x1, x2, y1, y2, b := 0
var slope, ang : real
x1 := 100

y1 := 100

loop
    mousewhere (x2, y2, b)
    drawline (0, y1, 640, y1, 12)
    if not (x2 = x1) then
        slope := (y2 - y1) / (x2 - x1)
    end if
    ang := arctand (slope)
    locate (1, 1)
    put "coords : ", x1, "/", y1, "/", x2, "/", y2
    put "slope : ", slope
    put "angle :", ang
    drawline (x1, y1, x2, y2, 9)
    delay (5)
    View.Update
    cls
end loop
Catalyst




PostPosted: Wed Jul 02, 2003 12:15 am   Post subject: (No subject)

there some problems there
such as the negative angles and the fact and from 180 to 270 show as 0-90
Homer_simpson




PostPosted: Wed Jul 02, 2003 12:37 am   Post subject: (No subject)

lol well yeah... but it is fixable if you try to fix it... i have fixed it and used it in my new particle engine with gravity support which i'll upload in a few minutes...
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 29 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: