ActionScript 3 三角方程创建椭圆
我正在使用此函数,该函数将对象围绕完美圆的中心点移动,并尝试修改它以将其移动为椭圆形,高度为宽度的 1/2?
基本上,我有一个设定的速度
var myVelocity:Number = 0.25;
,然后根据速度计算正弦和余弦
var myCos:Number = Math.cos(myVelocity);
var mySin:Number = Math.sin(myVelocity);
,然后计算物体沿每个轴距固定中心点的距离,
var x1:Number = myBall.x - centerX;
var y1:Number = myBall.y - centerY;
var x2:Number = myCos * x1 - mySin * y1;
var y2:Number = myCos * y1 + mySin * x1;
myBall.x = centerX + x2;
myBall.y = centerY + y2;
我还有另一个函数根据 myBall.x 计算 x 和 y = 中心X + cos(角度) * 半径;将半径修改为椭圆形很容易,但是有没有一种简单的方法可以将上面的半径修改为椭圆形呢?我想这样做是为了提高代码效率并减少数学函数调用的数量
I am working with this function that moves an object around a center point in a perfect circle and am trying to modify it to move it in an oval shape that is 1/2 as high as it is wide?
Basically, I have a set speed
var myVelocity:Number = 0.25;
then I calculate my Sine and Cosine based on the speed
var myCos:Number = Math.cos(myVelocity);
var mySin:Number = Math.sin(myVelocity);
then I figure the distance of the the object from a fixed center points along each axis and
var x1:Number = myBall.x - centerX;
var y1:Number = myBall.y - centerY;
var x2:Number = myCos * x1 - mySin * y1;
var y2:Number = myCos * y1 + mySin * x1;
myBall.x = centerX + x2;
myBall.y = centerY + y2;
I have another function that figures x and y based upon myBall.x = centerX + cos(angle) * radius; that is easy enough to modify the radius to become an ellipse, but is there an easy way to mod the one above to become an ellipse? I want to do this to be more efficient with the code and reduce the number of math function calls
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题几乎逐字逐句地反映了 Keith Peters 在 基础 Actionscript 3.0:让事物动起来!< /a>
我从书中为您摘录了一个快速片段。
结果:http://www.swfupload.com/view/155573.htm
This question is nearly verbatim to what Keith Peters covers in Foundation Actionscript 3.0: Making Things Move!
I've whipped up a quick snippet for you from the book.
Result: http://www.swfupload.com/view/155573.htm