轨道对象周围中心点 [英] Orbit Object Around Center Point

查看:156
本文介绍了轨道对象周围中心点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图轨道围绕中心点的对象,就像太阳和行星的我们。不过我有没有在所有的运气。任何帮助将是真正伟大的。谢谢。我写的卢娜,我不认为这是对这里的类别,但是这可能是只是一般code。但是,如果在错误的地方,我向你道歉。

 本地函数动画(事件)    当地拉德=度*(Math.PI / 180);
    ballOne.x = 20 * Math.cos(弧度);
    ballOne.y = 20 * Math.sin(弧度);
    度=度+ 1结束运行时间:调用addEventListener(一个enterFrame,动画)


解决方案

您可以尝试20.0和180.0迫使他们浮点,否则你的计算可能最终会被整,不会很好地工作,否则,一切似乎都很好。

另外,我建议一个单元测试两本。如果在0,90,180和260传给你应该得到偶数出(+/- 20,0或0,20)。这将帮助你调整它,让你相信的结果。

- 编辑 -
写下你的程序的常规版本,因为我不认识你的很多code的。发现与拉德VS拉德问题(在评论中提到的)。这是你的算法的常规转储:

 浮度= 0.0
浮拉德=度*(Math.PI / 180.0);
浮动X = 20.0 * Math.cos(拉德);
浮Y = 20.0 * Math.sin(拉德);
度=度+ 1
的println点¯x
ÿ的println

这工作。我通过单元测试的意思是,你可以设置一些与0.0度调用你的方法,并确保输出有20.0 x和0.0 Y,然后用90调用它,你应该得到0,20(其实你可能会得到一个轻微的浮点错误,只是测试看到,x小于0.001或东西)

如果您使用的是谷歌批准的框架来开发这些应用程序,我100%肯定会有一些官方的方式做单元测试,我强烈建议你看看吧,尤其是动态语言的单元测试可以是绝对关键的。

一单元测试的最重要的部分是,你可以用你的开发环境中单点触摸运行它们。这确保了无论你添加的内容code,即用来工作一切仍然有效。它可以给你信心去重构现有的code,而不必担心破坏的东西,你甚至不知道互动。

大多数谁动态语言工作的人考虑单元测试的绝对要求,而且即使在静态类型语言它们作为你的项目的发展超出了一个平凡的大小非常重要的。

I am attempting to orbit an object around a center point, much like the sun and our planets. However I am having no luck at all. Any help would be really great. Thanks. I'm writing in luna and I dont think there is a category for that here, but this probably is just general code. But if its in the wrong place, my apologies.

local function animate(event)

    local rads = degrees * (Math.PI / 180);
    ballOne.x = 20 * Math.cos(rad);
    ballOne.y = 20 * Math.sin(rad);
    degrees = degrees + 1

end

Runtime:addEventListener("enterFrame", animate)

解决方案

You might try 20.0 and 180.0 to force them to floating point, otherwise your calculations might end up being integer which won't work well, otherwise everything seems fine.

Also I suggest a unit test or two for this. If you pass in 0, 90, 180 and 260 you should get even numbers out (+/- 20,0 or 0,20). That will help you tweak it and let you believe in the results.

-- edit -- Wrote a groovy version of your program because I don't recognize a lot of your code. Found a problem with rad vs rads (mentioned in the comments). Here's a groovy dump of your algorithm:

float degrees=0.0
float rads = degrees * (Math.PI / 180.0);
float x = 20.0 * Math.cos(rads);
float y = 20.0 * Math.sin(rads);
degrees = degrees + 1
println x
println y

This works. What I meant by unit test is that you can set up something that calls your method with "0.0" degrees and ensure that the output has x of 20.0 and y of 0.0, then call it with 90 and you should get 0,20 (Actually you may get a slight floating point error, just test to see that x is less than .001 or something)

If you are using a google-approved framework to develop these apps I'm 100% sure there will be some "Official" way to do unit testing, I highly recommend you look into it, especially with a dynamic language unit tests can be absolutely critical.

One of the most important parts of unit tests is that you can run them all with a single touch inside your development environment. This ensures that no matter what code you add, everything that used to work still works. It can give you confidence to go and refactor existing code without worrying about breaking something you didn't even know interacted.

Most people who work in dynamic languages consider unit tests an absolute requirement, and even in statically typed languages they are very important as your project grows beyond a trivial size.

这篇关于轨道对象周围中心点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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