游戏中的数学逻辑(基本三角函数),这段代码在做什么?

发布于 2024-08-05 17:59:39 字数 358 浏览 3 评论 0原文

我试图更好地理解这段代码到底在做什么。它是用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

世俗缘 2024-08-12 17:59:39

这是圆的参数方程(参见维基百科

我猜“度”变量实际上是弧度而不是度数。圆有 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文