rotations on a line list

Started by
3 comments, last by l3arknight 20 years, 8 months ago
I am trying to understand the math for rotating a line list in the shape of a triangle. Here is the code: //vertex 0 g_vertices [ 0 ].x = SCREENWIDTH / 2 + cos ( g_angle ) * RADIUS ; g_vertices [ 0 ].y = SCREENHEIGHT / 2 + sin ( g_angle ) * RADIUS ; //vertex 1 g_vertices [ 1 ].x = SCREENWIDTH / 2 + cos ( g_angle + 2.0 * PI / 3.0 ) * RADIUS ; g_vertices [ 1 ].y = SCREENHEIGHT / 2 + sin ( g_angle + 2.0 * PI / 3.0 ) * RADIUS ; //vertex 2 g_vertices [ 2 ].x = SCREENWIDTH / 2 + cos ( g_angle + 2.0 * PI / 3.0 ) * RADIUS ; g_vertices [ 2 ].y = SCREENHEIGHT / 2 + sin ( g_angle + 2.0 * PI / 3.0 ) * RADIUS ; //vertex 3 g_vertices [ 3 ].x = SCREENWIDTH / 2 + cos ( g_angle - 2.0 * PI / 3.0 ) * RADIUS ; g_vertices [ 3 ].y = SCREENHEIGHT / 2 + sin ( g_angle - 2.0 * PI / 3.0 ) * RADIUS ; //vertex 4 g_vertices [ 4 ].x = SCREENWIDTH / 2 + cos ( g_angle - 2.0 * PI / 3.0 ) * RADIUS ; g_vertices [ 4 ].y = SCREENHEIGHT / 2 + sin ( g_angle - 2.0 * PI / 3.0 ) * RADIUS ; //vertex 5 g_vertices [ 5 ].x = SCREENWIDTH / 2 + cos ( g_angle ) * RADIUS ; g_vertices [ 5 ].y = SCREENHEIGHT / 2 + sin ( g_angle ) * RADIUS ; //increase angle for next time g_angle += ( 2.0 * PI / 360.0 ) ; I am not following the math at all. If someone could point me in the right direction I would greatly appreciate it. Thanks in advance.
Advertisement
Have you taken any geometry and/or trigonometry? This is hard to explain unless you understand the basic concepts of the unit circle, right triangles, and properties of similar triangles.

To give you a brief synopsis, the cosine of an angle represents the length of the base/adjacent of a triangle with hypotenuse length 1 (which can be inscribed within a unit circle, hence the unit length), angle being that between said base and hypotenuse. You then scale by RADIUS. Sine is similar, only it represents the length of the "vertical"/opposite side of said triangle. The addition of SCREEN* / 2 is simply to translate the triangle to the middle of the screen.

[edited by - Zipster on August 6, 2003 7:17:10 PM]
Yes I have had all that stuff. I understand the trig/geometry concepts. I am not following why he is using in the argument of the trig functions. I understand that the screenwidth/2 is just a shifting factor and that the RADIUS is a scaling factor. I mean is he divideing the large triangle into 2 different triangles. My major problem is why he is doing g_angle + 2.0 * PI / 3.0 for some arguments and g_angle - 2.0 * PI / 3.0 for others. Why is he multilplying by PI. Why is he dividing by 3 and where is the 2 coming from.

[edited by - l3arknight on August 6, 2003 8:09:25 PM]

[edited by - l3arknight on August 6, 2003 8:32:13 PM]

[edited by - l3arknight on August 6, 2003 8:33:10 PM]
Ah, I see. He is adding and subtracting 2PI/3 from the angle, which is equivalent to 120 degrees. This positions the points in a triangular fashion. The first point is at some angle, and then the other two points are at +/- 120 degrees from the first point. From the looks of the code, it appears he is making two copies of the exact same triangle, as the same math is used for multiple vertices (vertex 1 and 2, vertex 3 and 4, vertex 0 and 5). Can't tell you why though.

And multiplying 2 by PI/360 is a sneaky way of computing 1 degree, as it evaluates to PI/180, which is the standard conversion factor you'd use for converting degrees to radians. It's simply increasing the angle by a single degree.

[edited by - Zipster on August 6, 2003 10:03:05 PM]
Thanks. I see now.

This topic is closed to new replies.

Advertisement