December 22nd, 2010, 03:26 PM
Set Sided Polygon in C++
Hello basically I've been working on this for 2 days now, I'm completely stuck. I've looked around the internet and can't really find anything in relation.
I have a program that I've created, It makes shapes. I've managed to make a draw line function & a square function.
Now it's sort of like a pixel plotter, with X & Y as the view ports.
I'm struggling to create a polygon with a given number of sides i.e. the user inputs how many sides that want.
Any help would be much appreciated, also I'm pretty rubbish at triangularly and that kinda stuff, so noobish explanations please!
This is what I got so far, still hasn't managed to figure out what i need next :-(
// Draw a regular polygon with the given number of sides. The centre of the polygon will be at
// (X, Y) and the points are on a circle of radius R
void PixelPlotterForm::DrawPolygon( int Sides, int X, int Y, int R, Color PixelColour )
int x = X;
int y = Y;
int r = R;
int sides = Sides;
float cir = PI * (r * 2);
float edgelength = cir / sides;
float tempsides = 0;
float angle = 360 / sides;
while(tempsides < sides)
//set view port pixel, this acually places the pixel on the program, X, Y and colour (ignore colour for now, it works)
SetViewportPixel(x + r, y + r, PixelColour);
r = r + angle;
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.