【问题标题】:How do I display a full 360 degrees using Actionscript 2 and Trigonometry?如何使用 Actionscript 2 和三角函数显示完整的 360 度?
【发布时间】:2012-04-04 21:18:34
【问题描述】:

我正在创建一个游戏,它使用三角函数来计算并在动态文本框中显示距离和度数。我正在计算光标与影片剪辑中心的距离。并使用影片剪辑的中心,当我的光标在 swf 周围移动时,我试图计算并显示一个完整的 360º。我有游戏的距离部分工作,但显示度数的部分工作不正常。动态文本框仅从 90º 到 270º 显示。它不是从 270º 到 360º/0º 到 90º,而是从 270º 倒数到 90º。下面是我的动作脚本。我非常感谢任何帮助或建议。谢谢!

//Mouse and Dynamic Text Boxes-------------------------

Mouse.hide();

onMouseMove = function () {
feedback.text = "You are moving your mouse";
cursor._x = _xmouse;
cursor._y = _ymouse;
updateAfterEvent();
xmouse_value.text = Math.atan2((a), (b));
ymouse_value.text = Math.round(radians*180/Math.PI)
updateAfterEvent();  
};

Mouse.addListener(myListener);


//distance (RANGE)
_root.onEnterFrame = function () {
xmid = Stage.width/2;
ymid = Stage.height/2;

a = _root._ymouse-ymid;
b = _root._xmouse-xmid;
c = Math.sqrt(Math.pow(a, 2)+Math.pow(b, 2));
feedbacka.text = Math.round(a);
feedbackb.text = Math.round(b);
feedbackc.text = Math.round(c/30.4);

updateAfterEvent();  

var radians:Number;
var degrees:Number;

//Calculcate Radians
//Radians specify an angle by measuring the length around the path of the circle.
radians = Math.atan2((c), (b))

//calculate degrees
//the angle the circle is in relation to the center point
//update text box inside circle
radians_txt = Math.round(radians*360/Math.PI);
degrees_txt = Math.round(radians*180/Math.PI);

updateAfterEvent();  

//getting past 270 degrees

radians2_txt = Math.round(radians/Math.PI);
radians2_txt = Math.floor(radians + -270);

}

【问题讨论】:

    标签: actionscript-2 distance trigonometry degrees


    【解决方案1】:

    atan2 的参数应该是两点之间的 delta-y 和 delta-x,但您传递的是两点之间的距离和 delta-x。试试这个:

    radians = Math.atan2(a, b);
    

    下一个问题是将弧度转换为度数。要将弧度转换为度数,您可以这样做:

    degrees_txt = radians * 180 / Math.PI;
    

    请注意,atan2-Math.PI / 2Math.PI / 2 之间返回。转换为度数时,该范围变为 -180 到 180。要转换为 0 到 360,如果结果为负数,可以将 360 添加到结果中:

    if(degrees_txt < 0) degrees_txt += 360;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-08
      • 1970-01-01
      • 1970-01-01
      • 2011-02-03
      • 1970-01-01
      • 2022-11-16
      • 1970-01-01
      相关资源
      最近更新 更多