游戏中的数学逻辑(基本三角函数),这段代码在做什么?
我试图更好地理解这段代码到底在做什么。它是用 Objective-C 编写的,但具有 C 背景的任何人都应该熟悉。正弦/余弦数学到底在做什么?另外,对于学习此类游戏概念的三角函数,有人有好的建议吗?
for (int i = 0; i < GAME_CIRCLES; i++)
{
point.x = center.x - sin (degree) * RADIUS;
point.y = center.y + cos (degree) * RADIUS;
mPieRect[i] = CGRectMakeWithCenter (point, RADIUS - 4);
degree += PI / 3.0;
}
I'm trying to better understand what exactly this code is doing. It's written in Objective-C, but should be familiar to anyone with a C background. What exactly are sin/cos mathematics doing here? Also, does anyone have a good recommendation for learning trig for gaming concepts such as these?
for (int i = 0; i < GAME_CIRCLES; i++)
{
point.x = center.x - sin (degree) * RADIUS;
point.y = center.y + cos (degree) * RADIUS;
mPieRect[i] = CGRectMakeWithCenter (point, RADIUS - 4);
degree += PI / 3.0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是圆的参数方程(参见维基百科)
我猜“度”变量实际上是弧度而不是度数。圆有 360 度,即 2*Pi 弧度。
通过将角度变量前进 Pi/3,它会步进大约 1/6 圆
That is the parametric equation for a circle (see wikipedia)
I'll guess that the "degree" variable is actually in radians rather than degrees though. There are 360 degrees in a circle, or 2*Pi radians.
By advancing the degree variable by Pi/3, it's stepping around 1/6 of a circle