Turing Programming: Solve Cos Inverse Function

In summary, the language Turing doesn't have a cos/sin inverse function, so you can't get angle I want using the normal cosine function. You could try looking up the Taylor series for inverse cosine on Google, but it's not the best way.
  • #1
eax
61
0
Hi,

I'm programming a game and need a character to turn facing another character. I got far but the problem is the language(Turing) Iam provided with doesn't support a cos/sin inverse function but has sin/cos.

Anyone know the formula? I have cos(x) how can I get x? Searching on google is not help all I get is what cos (x) = to relative to sin/tan.

Thanks in advance!
 
Physics news on Phys.org
  • #2
Hi
I am not sure about your question but I will try my best to anwser it...
Cosine(x)= adj/hyp.
cos(x)^-1= Ratio of the adjecent arm to the ratio of the hypotines.

Or in terms of the unit circle...
Cos(x) is equal to x/r
so...
Cos(x)^-1= Ratio of x/r. THis solves for the angle of x.

Ok and finally...
cot(x)=cos(x)/sin(x)
the inverse of Cos(x) is sec(x) ie. sec(x)=r/x
the inverse of Sin(x) is csc(x) ie. csc(x)=r/y
I hope that helped...
The ratio of sin(x)/
 
  • #3
This is what I have for mouse to character interaction, instead of character(enemy) to character(player)

Code:
set x/y to equal mouse position x/y
x := mousex
y := mousey
drawx/yoff are < 0 but we want to add them to x/y thus
subtracting adds them to x/y
x -= drawxoff
y -= drawyoff


bound.x/y are the coordinates for the character(player)
subtracting x/y by bound.x/y gives the x/y position reveloving
bound.x/y so (0,0) = (bound.x, bound.y)
y -= bound.y
x -= bound.x
get distance
dist := sqrt (x * x + y * y)
if dist < 1 then
    return
end if

I added 90 for a reason but it doesn't matter
pangle += 90
this next function just makes sure pangle is >= 0 and <= 360
rapanglei (pangle)

cos_t is a table of cos values because calculating cos everytime takes
lots of CPU time

calculating dotproduct (I think that's what it is called)
(and I like to reuse variables to save memory :))

We are treating these as vectors. bound.r = radius of character(player)
multiplying by cos(angle) gives us the "vector" its facing, then calculating
dot product 
x := (x * cos_t (pangle) * bound.r + y * sin_t (pangle) * bound.r) / (bound.r * dist)
puting pangle back to original value
pangle -= 90

and now x = cos(angle I want)
angle I want = cos inverse(x)

There is no cos/sin inverse function in this language. How can I get "angle I want"?
I hope my question is more clear now

Thanks in advance!
 
  • #4
Maybe you could make an arccos() look-up table? I don't know of any mathematical way to transfer cos(x) to x without arccos(). A look-up table would probably be faster anyways. You'd just need to make a function that finds the closest related value.

By the way, I've never seen the language Turing, but it kind of looks like Pascal...
 
  • #5
Im not even sure if http://www.holtsoft.com/turing/support/#currentversion is a language. Its more of an interpreter, I don't know why my school starts of with Turing then C++ is next year(or cemester :)). It would be better to start with C/ASM (in 16bit(DOS) mode)

Someone has to know. My math teacher said that before there were calculators people new the formula's for cos/sin and arccos/sin. If everyone forgot then everyone just copy's and pastes code into calculators and every where else :D.
 
Last edited by a moderator:
  • #6
I'm pretty sure there's a Taylor series for all the trigonometric functions, but I can't seem to find the one for arccos(). Try looking up on Google the Taylor series for inverse cosine, and see if you can find it.

Learning an interpreted language before a compiled one? That's quite odd.
 
  • #7
nolachrymose said:
Try looking up on Google the Taylor series for inverse cosine, and see if you can find it.d.

You could use the derivative of cos^-1 x and work out it's Taylor series, then integrate term by term.
 
  • #8
Hi,
I am not an anvanced programmer, but anyway, I suggest this:
Since you know cos(x) then you know it's positive/negative/0.

If cos(x) = 0 then
x = 90
EndIf

If cos(x) < 0 then
For s = 91 to 180
...
(You can find the difference between cos(x) and cos(s). When the cos(s) - cos(x) < 0, stop the loop and you will get the s).
Next s
EndIf

If cos(x) > 0 then
For s = 1 to 90
...
(You can find the difference between cos(x) and cos(s). When the cos(s) - cos(x) > 0, stop the loop and you will get the s).
Next s
EndIf

And you will get cos(s) approximetely equal to cos(x)... But it's not the best way, though,...
Hope this help :-)
Bye bye,
Viet Dao,
 
  • #9
Thank you :)
 

Related to Turing Programming: Solve Cos Inverse Function

1. What is Turing programming?

Turing programming is a high-level programming language that was created in the 1980s by Niklaus Wirth. It is named after the mathematician and computer scientist Alan Turing.

2. What is the Cos Inverse Function?

The Cos Inverse function, also known as ArcCos or Inverse Cosine, is the inverse of the cosine function. It is used to find the angle in radians that has a cosine value equal to a given number.

3. How do you solve the Cos Inverse Function in Turing programming?

In Turing programming, the Cos Inverse function can be solved using the arccos function. This function takes in a number as its argument and returns the angle in radians.

4. What is the syntax for using the Cos Inverse function in Turing programming?

The syntax for using the Cos Inverse function in Turing programming is arccos(x), where x is the number for which you want to find the angle in radians.

5. Is the Cos Inverse function available in all versions of Turing programming?

Yes, the Cos Inverse function is a built-in function in Turing programming and is available in all versions of the language. It can be used in both console programs and graphics programs.

Similar threads

  • Introductory Physics Homework Help
Replies
21
Views
2K
  • Introductory Physics Homework Help
Replies
6
Views
2K
Replies
2
Views
1K
  • Programming and Computer Science
Replies
29
Views
3K
  • Topology and Analysis
Replies
6
Views
1K
Replies
5
Views
971
  • Calculus and Beyond Homework Help
Replies
2
Views
271
  • Introductory Physics Homework Help
2
Replies
35
Views
2K
  • Introductory Physics Homework Help
Replies
15
Views
5K
Replies
2
Views
1K
Back
Top