-
October 17th, 2019, 04:14 AM
#16
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++;
}
}
Last edited by VictorN; October 17th, 2019 at 04:24 AM.
Reason: added code tags
-
October 17th, 2019, 04:25 AM
#17
Re: Set Sided Polygon in C++
Victor Nijegorodov
-
October 17th, 2019, 04:27 AM
#18
Re: Set Sided Polygon in C++
Yes, Is there any error in code?
-
October 17th, 2019, 06:10 AM
#19
Re: Set Sided Polygon in C++
 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!
Victor Nijegorodov
-
October 17th, 2019, 06:49 AM
#20
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.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.2)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|