Re: Set Sided Polygon in C++
Code:
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)
{
SetViewportPixel(x + r, y + r, PixelColour);
r = r + angle;
tempsides++;
}
}
Re: Set Sided Polygon in C++
Re: Set Sided Polygon in C++
Yes, Is there any error in code?
Re: Set Sided Polygon in C++
Quote:
Originally Posted by
basilmon
Yes, Is there any error in code?
Usually the compiler shows you all syntax errors.
To find out and fix the design error one has to use the debugger!
Re: Set Sided Polygon in C++
Your code in post #16 is based upon the old code from post #1 - which is incorrect. As a minimum, it should be based upon the code from post #8. From your code,
- edgelength isn't the edge length but the length of the sector arc.
- tempsides should be int not float as sides is a whole number.
assuming R is the radius length of the circumscribed circle and X, Y the centre co-ordinates of the circle, then you need to first determine the initial point on the circle then for each loop, r doesn't change but x and y do based upon angle.