• 10
• 9
• 12
• 14
• 15

My octagon is a circle and my pentagon is wonky :'(

This topic is 737 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Its me the shape guy :/

Ok, i spent most of to trying to figure this out but I've hit a brick wall mentally, I output and image of a diamond and its all good, lines are straight and looks nice, I add functionality to draw a octagon and a pentagon and things stop drawing correctly.

The pentagon isn't far off but there's a few (x,y) * out of place but the octagon is...well...its a damn circle <_<

I use a formula of rotation based on the shapes centroid, with the octagon the vertices would be 72 degrees apart, in total 360 degrees with 5 points. Its just not happening for some reason. I have tried apply different degrees, looking at the draw line algorithm, clearing the vertices list before adding new vertices (just in case it was using vertices for other shapes) but still the issue persists.

The code below is the function for plotting the vertices of the octagon:

void octagon::plotVertices()
{
int x, y, xx, yy;

x = centroid.getX();
vertices.push_back(Vertex(x, y));

x = vertices.back().getX() - centroid.getX();
y = vertices.back().getY() - centroid.getY();

radians = 45 * PI / 180;
xx = xx + centroid.getX();
yy = yy + centroid.getY();
vertices.push_back(Vertex(xx, yy));

radians = 90 * PI / 180;
xx = xx + centroid.getX();
yy = yy + centroid.getY();
vertices.push_back(Vertex(xx, yy));

radians = 135 * PI / 180;
xx = xx + centroid.getX();
yy = yy + centroid.getY();
vertices.push_back(Vertex(xx, yy));

radians = 180 * PI / 180;
xx = xx + centroid.getX();
yy = yy + centroid.getY();
vertices.push_back(Vertex(xx, yy));

radians = 225 * PI / 180;
xx = xx + centroid.getX();
yy = yy + centroid.getY();
vertices.push_back(Vertex(xx, yy));

radians = 270 * PI / 180;
xx = xx + centroid.getX();
yy = yy + centroid.getY();
vertices.push_back(Vertex(xx, yy));

radians = 315 * PI / 180;
xx = xx + centroid.getX();
yy = yy + centroid.getY();
vertices.push_back(Vertex(xx, yy));

radians = 360 * PI / 180;
xx = xx + centroid.getX();
yy = yy + centroid.getY();
vertices.push_back(Vertex(xx, yy));
}


below is an image of the output:

:(

Share on other sites

:)

	int x, y, xx, yy;

x = centroid.getX();
vertices.push_back(Vertex(x, y));

x = vertices.back().getX() - centroid.getX();
y = vertices.back().getY() - centroid.getY();

int degree = 72;
for (int i = 0; i < 5; i++)
{
radians = degree * PI / 180;
xx = xx + centroid.getX();
yy = yy + centroid.getY();
degree = degree + 72;
vertices.push_back(Vertex(xx, yy));
}


still wonky tho :P

Edited by homi576

Share on other sites
You haven't shown us what your pentagon looks like.

Share on other sites

You haven't shown us what your pentagon looks like.

You have to buy me dinner first, just kidding.

The link in the original post shows the output

Share on other sites

The link in the original post shows the output

No, it doesn't. The pentagon is truncated.

Share on other sites

Is the weird appearance just due to the non-square grid that you're drawing to?

Share on other sites

Each cell of the console is not perfectly square. By default, on Win10, for example, my console cells are 8x16. They are twice as large as they are wide.

Also, the asterisk isn't centered properly in the cell, so try outputting a character like this.