How do I use Trigonometrical functions in scripts?

Asked by Archie Howitt on 2020-07-09

I am writing a script in which I want to use Trigonometrical functions cosine and sine but when I write something like:

x = cos(45);

I get an error:
"ReferenceError: Can't fine variable cos"

Is there a library that I must include?

Archie

Question information

Language:
English Edit question
Status:
Solved
For:
Stellarium Edit question
Assignee:
No assignee Edit question
Solved by:
Archie Howitt
Solved:
2020-07-09
Last query:
2020-07-09
Last reply:
Archie Howitt (dunedin) said : #2

Hi
I've just solved this myself by reading Qaml's script Jupiter Ephemeris - Thanks Qaml.

Qaml shows you have to use radians so:

x=Math.cos(45 * 0.0174533);

or as Qaml shows:

pi = 3.14159265358979323846264338327950288419716939937510;
rad = pi/180;
deg = 180/pi;

Archie

Oops!