Trig如何在JavaScript中工作? [英] How does trig work in JavaScript?

查看:99
本文介绍了Trig如何在JavaScript中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个值及其余弦为:

I have a value and its cosine as:

-0.2567721374914637
Cosine: -0.04253775592822526

比较我们在Python中得到的东西:

Compare what we get in Python:

>>> import math
>>> math.cos(-0.2567721374914637)
0.9672147629178562

有没有一种方法可以用JavaScript进行午餐以外的事情?

Is there a way I can do trig in JavaScript that isn't out to lunch?

有没有数学库或任何可提供三角函数的东西?

Are there any math libraries or anything that provide working trigonometry?

-编辑-

报告结果的代码是:

            var distance_along = (high_noon.getTime() / 1000 -
              summer_solstice.getTime() / 1000)
              / (winter_solstice.getTime() / 1000
              - summer_solstice.getTime() / 1000);
            console.log(distance_along);
            console.log('Cosine: ' + Math.cos(2 * Math.PI * distance_along));
            var added_degrees = (Math.cos(2 * Math.PI * distance_along) * 
              ANCIENT_CLOCK.earth_tilt);

报告的距离为

-0.2567721374914637
Cosine: -0.04253775592822526 

关于查找事物的问题:我没有对如何处理余弦进行广泛的查找.我知道JavaScript有一个Math库,并且认为查找它的逻辑位置是在Math.cos()中.但是,它报告了上面的值.

Regarding the question of looking things up: I did not do extensive looking up of how to handle a cosine. I knew that JavaScript had a Math library, and thought the logical place to look for it was in Math.cos(). However, it reported the values above.

推荐答案

您可以这样执行javascript:

You can do this javascript like this:

//Return the cosine of a number:
Math.cos(3);
// -0.9899924966004454

您可以在此处获取Math对象的完整列表: JavaScript数学对象

You can get the full list of Math objects here: JavaScript Math Object

这篇关于Trig如何在JavaScript中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆