randombits
randombits

Reputation: 48490

Math logic (basic trig) in a game, what is this code doing?

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;
}

Upvotes: 2

Views: 890

Answers (1)

Paul Dixon
Paul Dixon

Reputation: 301055

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

Upvotes: 7

Related Questions