Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualSpirrwell

Posted 16 November 2012 - 10:48 PM

[Trigonometric Knowledge Useful!]

Alright, I'm trying to create my own version of a circle by using triangles, I guess right now my intended circle will be an octagon because it has 8 sides, well it will.

So far I have this one triangle:

Posted Image

The two sides on the left and right is known as r for radius which is equal to half of the window's height. Since I was going to try to deal with a circle with 8 "slices" the angle measure of the bottom angle has to be 45 degrees. and I use that to find the length of the top side which is done with this function:

double FindMissingSide(double a, double b, double C)
{
	 //ToRadians is a variable which is PI/180.0
	double c = sqrt(pow(a, 2.0) + pow(b, 2.0) - 2 * a * b * cos(C * ToRadians));
	return c;
}


I use it in my drawing code (Yes I know I'm calculating the unknown side every time, but this is a small project so I'm not worried):

glPushMatrix();
		glColor3f(1.0f, 1.0f, 1.0f);
		glTranslated((double)ScreenWidth/2.0, (double)ScreenHeight/2.0, 0.0);
		glBegin(GL_TRIANGLES);
		glVertex2d(0.0 - (FindMissingSide(r, r, 360.0/slices)/2), 0.0 - r);
		glVertex2d(0.0 + (FindMissingSide(r, r, 360.0/slices)/2), 0.0 - r);
		glVertex2d(0.0, 0.0);
		glEnd();
		glPopMatrix();

Now before I went and created a for loop, I decided I'd create another triangle and rotate 45 degrees with glRotated(45.0, 0.0, 0.0, 1.0);, which I would expect the two triangles to share one side, but it has a gap of about 3 degrees:

Posted Image

Now I said it seemed to have a gap of 3 degrees because if I set the x rotation to 42, it shares the side, but then it's off by 3 degrees, and the next triangle I would have to subtract 6 degrees because I already subtracted 3 from the last rotation.

I don't understand, I must be doing something plainly stupid and I don't see it. I would think that I must be calculating the missing side wrong somehow...

Any ideas?

#1Spirrwell

Posted 16 November 2012 - 01:22 PM

[Trigonometric Knowledge Useful!]

Alright, I'm trying to create my own version of a circle by using triangles, I guess right now my intended circle will be an octagon because it has 8 sides, well it will.

So far I have this one triangle:

Posted Image

The two sides on the left and right is known as r for radius which is equal to half of the window's height. Since I was going to try to deal with a circle with 8 "slices" the angle measure of the bottom angle has to be 45 degrees. and I use that to find the length of the top side which is done with this function:

double FindMissingSide(double a, double b, double C)
{
	 //ToRadians is a variable which is PI/180.0
	double c = sqrt(pow(a, 2.0) + pow(b, 2.0) - 2 * a * b * cos(C * ToRadians));
	return c;
}


I use it in my drawing code (Yes I know I'm calculating the unknown side every time, but this is a small project so I'm not worried):

glPushMatrix();
		glColor3f(1.0f, 1.0f, 1.0f);
		glTranslated((double)ScreenWidth/2.0, (double)ScreenHeight/2.0, 0.0);
		glBegin(GL_TRIANGLES);
		glVertex2d(0.0 - (FindMissingSide(r, r, 360.0/slices)/2), 0.0 - r);
		glVertex2d(0.0 + (FindMissingSide(r, r, 360.0/slices)/2), 0.0 - r);
		glVertex2d(0.0, 0.0);
		glEnd();
		glPopMatrix();

Now before I went and created a for loop, I decided I'd create another triangle and rotate 45 degrees with glRotated(45.0, 0.0, 0.0, 1.0);, which I would expect the two triangles to share one side, but it has a gap of about 3 degrees:

Posted Image

Now I said it seemed to have a gap of 3 degrees because if I set the x rotation to 42, it shares the side, but then it's off by 3 degrees, and the next triangle I would have to subtract 6 degrees because I already subtracted 3 from the last rotation.

I don't understand, I must be doing something plainly stupid and I don't see it. I would think that I must be calculating the missing side wrong somehow...

Any ideas?

PARTNERS