【问题标题】:Problem understanding sin(x)问题理解 sin(x)
【发布时间】:2011-04-22 07:47:38
【问题描述】:

嘿,偷看, 我得到了这个代码:

red = red + 1;
trace("red: " + red);
trace("Math.sin(red): " + Math.sin(red));
var newRed:uint = Math.abs(Math.sin(red)) * 255;
trace("newRed: " + newRed);

此代码输出以下内容:

red: 256
Math.sin(red): -0.9992080341070627
newRed: 254
red: 257
Math.sin(red): -0.5733571748155426
newRed: 146
red: 258
Math.sin(red): 0.37963562682930313
newRed: 96
red: 259
Math.sin(red): 0.9835931839466808
newRed: 250

等等

当我将 sin(257) 插入计算器时,我得到 -0.974370064785235,但 Flash 给出 -0.5733571748155426

编辑:-

但是,当我插入 sin(256) 时,我从每个中得到相同的数字。这让我很困惑。

我有点困惑为什么会这样。请帮忙。 亚历克斯

【问题讨论】:

标签: flash math trigonometry


【解决方案1】:

确保提供正确格式的输入参数。有些人可能希望参数以弧度表示角度,有些则以度数表示。

http://en.wikipedia.org/wiki/Sine?section=9#Properties_relating_to_the_quadrants

根据Action Script reference,sin 函数期望参数为弧度。

【讨论】:

  • 它应该返回与计算器相同的值。在这种情况下,我没有将 sin 用于角度测量,而是用于插值。
  • 如果提供了相同的输入值,它确实返回相同的值(在舍入误差内)。弧度和度数只是同一角度的两种不同表示。请参阅上面的维基百科文章。
  • 当我将 256 放入计算器时,得到的结果与 Flash 相同。但是当我输入 257 时,情况就不同了。你能解释一下吗?
  • 256 的结果是什么?你用的是哪个计算器?
  • Windows 计算:sin(256) -> 弧度:-0,99920803410706269906759056238387 度:-0,97029572627599647230637787403399
【解决方案2】:

Flash 使用弧度单位,计算器使用度数单位。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多