Computer Science Canada

Sine inverse

Author:  Martin [ 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

Author:  JSBN [ Sat Apr 26, 2003 12:20 pm ]
Post 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

Author:  octopi [ Sat Apr 26, 2003 1:08 pm ]
Post 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

Author:  jamez [ Sat Apr 26, 2003 7:54 pm ]
Post subject: 

octopi your code crashes Razz

Author:  octopi [ Sat Apr 26, 2003 8:10 pm ]
Post subject: 

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

I test in winoot 3 only.

Author:  nate [ 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

Author:  Tony [ Sat Apr 26, 2003 8:15 pm ]
Post 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

Author:  octopi [ Sat Apr 26, 2003 9:04 pm ]
Post subject: 

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

1.207418 raised to the -6
(also known as)
0.000001207418
So virtually zero.


: