Advertisement

VERY EASY MATH QUESTION

Started by March 30, 2002 01:46 AM
4 comments, last by haro 22 years, 11 months ago
Is there a way to calculate the coordinate position of a point lying on the circumference of a circle, other than saying: If that point is at 30degrees from the origin, then just rotate 30 degrees, move forward the radius and draw the circle? Particularly, if I have a box at 1,0,0 that is revolving around the origin at 0,0,0.. and I want to move it one degree counter clockwise at the next screen display, how would I determine its coordinates? I tried reasoning that in 90 degrees, the box''s x value will change a total of -1.0, so that each degree the x location would be shifted by -1.0/90 (for the first 180 degrees), and by the same reasonining, the y location goes from being 0 to 1, so it seems that the y value would change by a total of 1.0, so it would move by a value of 1.0/90 (for the first 180 degrees)... Anyhow, needless to say this was a complete flop, but I''m not really sure why.. Any help would be much appreciated!
sin and cos my friend


  float xPosition, yPosition;xPosition = cos(angle) * radiusOfCircle;yPosition = sin(angle) * radiusOfCircle;  



"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T
Advertisement
Thanks alot, you helped me an oddly large amount. I just realized, even as a sophomore in college, I never really knew what sin/cos were, even though I have countless pre-derived formulas memorized. The power I now have with truth behind sin and cos!! BWAHAHAH!!! SOON THE WORLD SHALL BE MINE!

Thanks.


Err... I''m puzzled. You''re a sothomore in college, you have alot of formulas with sin and cos memorized and you simply didn''t know the basics of them?
Mhm.
Well, eventhough the school doesn''t (normally) teach out rotations as such, there are alot of tutorials about that kind of thing.

posX = radius * cos(angle);
posY = radius * sin(angle);

Then we have an even MORE complicated formula:

posZ = z*cos(angle) - y*sin(angle);
posY = z*sin(angle) + y*cos(angle);

Have fun =)




Js
Js
void drawCirc(float dif)
{
float x1, x2, y1, y2;
glBegin(GL_LINES);

for(int i = 1; i <= 36; i++)
{
x1 = cos(i * dif);
y1 = sin(i * dif);
x2 = cos(i * dif + 10);
y2 = sin(i * dif + 10);
glVertex3f(x1, y1, 0.0);
glVertex3f(x2, y2, 0.0);
}
glEnd();
}


Starting "dif" at 1.0, and incrementing it by .002 every 300miliseconds, and constantly redrawing creates some pretty interesting looking 2d effects for 2 minutes of work.. think I''ll add a z value, and allow different view angles, would look even neater.

-Having fun with sin and cos!!






Ok, last code dump. Tweaked the previous code a little for some cheeeesy zoom type thing and better color.. hey, its an 8 minute screen saver. This uses glut.



float depth = -5.0;
float amount = 0.0;
bool deeper = true;


inline void drawCirc(float dif)
{
float x1, x2, y1, y2;
glBegin(GL_LINES);

for(int i = 1; i <= 36; i++)
{
x1 = cos(i * dif);
y1 = sin(i * dif);
x2 = cos(i * dif + 10);
y2 = sin(i * dif + 10);
glColor3f(0.2, 0.5, 0.9);
glVertex3f(x1, y1, 0.0);
glColor3f(0.6, 0.3, 0.8);
glVertex3f(x2, y2, 0.0);
}
glEnd();
}


void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0, 0.0, depth);
glColor3f (0.5, 0.8, 0.8);
amount += 0.0001;


drawCirc(amount);

glutSwapBuffers();
}

void idle(void)
{
if(deeper)
depth += 0.003;
else
depth -= 0.01;

if(depth > -0.6)
deeper = false;
if(depth < -5.0)
deeper = true;

glutPostRedisplay();
}


This topic is closed to new replies.

Advertisement