Re: Set Sided Polygon in C++
What does not work as you expected?
Re: Set Sided Polygon in C++
I do not understand your algorithm. Perhaps there is something I am missing. It seems to me that if one specifies a polygon with the number of sides greater than or equal to 3, there are an infinite number of possible such polygons. Thus one would need to specify the length of each side and some clever algorithm to determine the angles between each side (such algorithms exist - try google). For more details, see:
http://www.mathleague.com/help/geome...ns.htm#polygon
After further thought I realized you must by trying to inscribe a regular polygon ( all sides equal ) on a circle. You will need some algorithm to divide the circumference of the circle into N+1 segments, then draw lines from each segment point to the next going around the circle. The math shouldnt be to difficult. I would be interested in seeing how you solve the problem.
Hope this is helpful :)
Re: Set Sided Polygon in C++
I've almost got it figured, I've got it too do one side of the polygon when a given side is given.
Basically I'm struggling too create it with an infinite number of sides.
Re: Set Sided Polygon in C++
Anyone have any idea how I would do this, been trying to figure it out for ages!
Re: Set Sided Polygon in C++
Quote:
Originally Posted by
Mike Pliam
It seems to me that if one specifies a polygon with the number of sides greater than or equal to 3, there are an infinite number of possible such polygons.
A polygon with less than three sides is an interesting concept... :D Aside from that: The possibilities of any polygon (number of sides >= 3) are infinite unless you specify some parameters. Even if you postulate a regular polygon they're infinite unless you specify a center and a starting point (e.g.).
Quote:
Originally Posted by
abakiz
Basically I'm struggling too create it with an infinite number of sides.
Hint: A regular polygon with an infinite number of sides is a circle.
Aside from that: http://en.wikipedia.org/wiki/Polygon
Re: Set Sided Polygon in C++
I see what your saying, but what sort of algorithm could I do this with?
Re: Set Sided Polygon in C++
What I got so far:
Code:
int x = X;
int y = Y;
//The radious, half of the circle length
int r = R;
int sides = Sides;
float cir = PI * (r * 2);
//basically saying, the edgelength and shave off the bit when you curve it straight, so you get the true length of each side.
float edgelength = (cir / sides) - ((cir / sides) / PI);
//splitting the angle of the sides
float angle = cir / sides;
//you need to rotate or move the line to the next angle / side or something.
float EndX_Y;
Re: Set Sided Polygon in C++
The point on a circle centered on (xc,yc) with radius r are given by
x = xc + r*cos(angle)
y = yc + r*sin(angle)
Code:
void PixelPlotterForm::DrawPolygon( int Sides, int X, int Y, int R )
{
double xc = X;
double yc = Y;
double radius = R;
double angle_step = 2.0 * PI / static_cast<double>(Sides);
for (int i=0; i<Sides; ++i)
{
double angle = angle_step * i;
double x = xc + radius*cos(angle);
double y = yc + radius*sin(angle);
}
}
Re: Set Sided Polygon in C++
abakiz, did you manage to fix this issue? Im working on something similar and as I am new to this struggling with:
void PixelPlotterForm::DrawRectangle( int X, int Y, int Width, int Height, Color PixelColour )
Re: Set Sided Polygon in C++
did you get the whole code? I am stuck with this problem
Re: Set Sided Polygon in C++
could anyone help me with this problem?
Re: Set Sided Polygon in C++
Quote:
Originally Posted by
basilmon
could anyone help me with this problem?
What is the issue - you don't say??
Re: Set Sided Polygon in C++
When I run the code I only getting single pixel , not even a side of polygon.
Re: Set Sided Polygon in C++
Quote:
Originally Posted by
basilmon
When I run the code I only getting single pixel , not even a side of polygon.
And what is the code you run?
Could you post it?