• Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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;
	double radians;

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

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

	radians = 45 * PI / 180;
	xx = round(x * cos(radians) - y * sin(radians));
	yy = round(y * cos(radians) + x * sin(radians));
	xx = xx + centroid.getX();
	yy = yy + centroid.getY();
	vertices.push_back(Vertex(xx, yy));
	
	radians = 90 * PI / 180;
	xx = round(x * cos(radians) - y * sin(radians));
	yy = round(y * cos(radians) + x * sin(radians));
	xx = xx + centroid.getX();
	yy = yy + centroid.getY();
	vertices.push_back(Vertex(xx, yy));

	radians = 135 * PI / 180;
	xx = round(x * cos(radians) - y * sin(radians));
	yy = round(y * cos(radians) + x * sin(radians));
	xx = xx + centroid.getX();
	yy = yy + centroid.getY();
	vertices.push_back(Vertex(xx, yy));

	radians = 180 * PI / 180;
	xx = round(x * cos(radians) - y * sin(radians));
	yy = round(y * cos(radians) + x * sin(radians));
	xx = xx + centroid.getX();
	yy = yy + centroid.getY();
	vertices.push_back(Vertex(xx, yy));

	radians = 225 * PI / 180;
	xx = round(x * cos(radians) - y * sin(radians));
	yy = round(y * cos(radians) + x * sin(radians));
	xx = xx + centroid.getX();
	yy = yy + centroid.getY();
	vertices.push_back(Vertex(xx, yy));

	radians = 270 * PI / 180;
	xx = round(x * cos(radians) - y * sin(radians));
	yy = round(y * cos(radians) + x * sin(radians));
	xx = xx + centroid.getX();
	yy = yy + centroid.getY();
	vertices.push_back(Vertex(xx, yy));

	radians = 315 * PI / 180;
	xx = round(x * cos(radians) - y * sin(radians));
	yy = round(y * cos(radians) + x * sin(radians));
	xx = xx + centroid.getX();
	yy = yy + centroid.getY();
	vertices.push_back(Vertex(xx, yy));

	radians = 360 * PI / 180;
	xx = round(x * cos(radians) - y * sin(radians));
	yy = round(y * cos(radians) + x * sin(radians));
	xx = xx + centroid.getX();
	yy = yy + centroid.getY();
	vertices.push_back(Vertex(xx, yy));
}

below is an image of the output:

 

https://drive.google.com/file/d/0B1dEh7m__i2naEZqa01xR2ZZRG8/view?usp=sharing

 

:(

Share this post


Link to post
Share on other sites
Advertisement

:) 

	int x, y, xx, yy;
	double radians;

	x = centroid.getX();
	y = centroid.getY() + radius;
	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 = round(x * cos(radians) - y * sin(radians));
		yy = round(y * cos(radians) + x * sin(radians));
		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 this post


Link to post
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 this post


Link to post
Share on other sites
That looks like a perfectly good pentagon to me. If you are complaining that a 2-color display with a resolution of something like 20x20 isn't very good, I have to agree with you.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement