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

Username:   Password: 
 RegisterRegister   
 Sine inverse
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Martin




PostPosted: Sat Apr 26, 2003 11:37 am   Post subject: Sine inverse

Is there any way I can use sine inverse with turing? My problem is this:

I know the starting and ending points of a line, and I need to find the angle formed...ex:
code:

                   (x2,y2)
               / |
             /   |
           /     |
         /       |
(x1,y1)/ m___|__


solving for angle m

bleh the diagram's not too great, but I'm sure you get the idea
Sponsor
Sponsor
Sponsor
sponsor
JSBN




PostPosted: Sat Apr 26, 2003 12:20 pm   Post subject: (No subject)

u could use cos or sin ratio to figure it out, there is a tutorial for it.
and if u need the length of the angled line u could use pythagorium thyrum: A^2 + B^2 = C^2
octopi




PostPosted: Sat Apr 26, 2003 1:08 pm   Post subject: (No subject)

Had one way, but this ones much better.


code:
function arcsin ( x : real ) : real
  if (x = 1) then
     result 90
  else
     result arctand(sqrt(abs((x*x) / (1 - (x *x)))))
  end if
end arcsin

function arccos ( x : real ) : real
  if (x = 0) then
     result 90
  else
     result arctand(sqrt(abs((1 - (x *x)) / (x *x))))
  end if
end arccos

for i:1..90
   put arccos(cosd(i)) ..
   put " " ..
end for


--Modified it to work with 1, and 0
jamez




PostPosted: Sat Apr 26, 2003 7:54 pm   Post subject: (No subject)

octopi your code crashes Razz
octopi




PostPosted: Sat Apr 26, 2003 8:10 pm   Post subject: (No subject)

Not for me, what version do you use, and are you modifying it at all?

I test in winoot 3 only.
nate




PostPosted: Sat Apr 26, 2003 8:15 pm   Post subject: math

The reason its crashin is cause when you reach 90 degrees.
It messes up cause your dividing by 0.

Basically you don't you arcsin or arctan for something that is at 90 degrees?

???
Well, i am only in grade 9 so how do i know? (thats what i think)
???

-Nate
Tony




PostPosted: Sat Apr 26, 2003 8:15 pm   Post subject: (No subject)

Nate is right, but you need a function that works for 360+ degrees

so all you have to do is place a guard in the function...
code:

function arcsin ( x : real ) : real
if x*x not= 1 then
  result arctand(sqrt(abs((x*x) / (1 - (x *x)))))
else
    result 90
end if

end arcsin


although it still outputs a weird number instead of 0. I suppose it has something to do with the fact that its impossible for arcsin to be 0 Confused
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
octopi




PostPosted: Sat Apr 26, 2003 9:04 pm   Post subject: (No subject)

The weird number isn't that weird....
its:

1.207418 raised to the -6
(also known as)
0.000001207418
So virtually zero.
Sponsor
Sponsor
Sponsor
sponsor
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 1  [ 8 Posts ]
Jump to:   


Style:  
Search: