Again, talk to your teacher.
C++ Rotating 2D shape in list
Thanks to all the members for there advice. Its a shame the moderators a so pretentious and self righteous. Not a pleasant experience on this site, does not live up to its reputation.
We have a strict rule of not doing people's homework on the site.
We will gladly help with a specific error or a specific problem you are having on homework when someone is clearly working on it and stumbling over something small like a syntax error, but anything more is directed back to your teacher.
This pattern is common to nearly all programming forums and discussion boards.
You are not asking about that type of problem, something where there is a subtle error in your code. You have given us what appear to be the contents of your assignment and asked questions about topics your teacher should have covered.
All I'm asking is how to apply rotation to a vertices, whats the point in knowledge when you don't share it? I'm not asking you to do an assignment Im basically asking to be pointed in the direction of an explanation of the logic, the files provided were just to show what the aim was.
Asking you guys to do the assignment would not benefit me in the slightest, I don't know whether you have miss interpreted my intentions with this thread but I want to learn how to do this, I am not a programming wiz kid or pick up a computer and automatically find myself in the matrix but I am committed to learning programming,
Sorry but it makes me angry that your implying I am here to get someone to do an assignment for me just to get a grade.
I'm not a little kid fresh in school, I'm 25 studying a degree and just need a helping hand which is difficult to get when 500 other people are trying to get that as well.
All I'm asking is how to apply rotation to a vertices,
Like this:
// first translate the object to the origin of the graph (0,0)// then apply the rotation formula to each vertex of the shape// finally, translate the object back to its original centroid
While that might be a bit snarky of me, the quoted explanation is a very thorough explanation of the solution.
whats the point in knowledge when you don't share it?
So how far did you get with my suggestion to start with a translation of a single vertex?
We don't mind helping you, but "explaining the logic" is either the sentences you already have as comment in your assignment, or the actual code. To me, there is nothing in between, and the latter is exactly the solution you don't even want.
As such, I have no idea whatsoever what you don't understand, or where you are stuck. You haven't shown anything either, so I have nothing to point out where you make the wrong turn.
No doubt it's a simple communication problem, but that happens when you discuss something with a bunch of strangers across a text-only medium. A face-to-face discussion with someone like your teacher, is really a lot better in these cases.
So how far did you get with my suggestion to start with a translation of a single vertex?
We don't mind helping you, but "explaining the logic" is either the sentences you already have as comment in your assignment, or the actual code. To me, there is nothing in between, and the latter is exactly the solution you don't even want.
As such, I have no idea whatsoever what you don't understand, or where you are stuck. You haven't shown anything either, so I have nothing to point out where you make the wrong turn.
No doubt it's a simple communication problem, but that happens when you discuss something with a bunch of strangers across a text-only medium. A face-to-face discussion with someone like your teacher, is really a lot better in these cases.
When you put it like that I see your position. I have gone away and had a look at working on applying the function to one vertices as such here is what I have so far, unfortunately it does not rotate the shape but moves it to the right instead.
Could you give a nod if I'm heading in the right direction or way off.
void Shape::rotate(double degrees)
{
int x, y, xx, yy;
double radians;
x = vertices.back().getX() - centroid.getX();
y = vertices.back().getY() - centroid.getY();
int testX;
int testY;
list<Vertex>::iterator current = vertices.begin();
while (current != vertices.end())
{
testX = (*current).getX();
testY = (*current).getY();
radians = degrees * PI / 180;
xx = round(x * cos(radians) - y * sin(radians));
yy = round(y * cos(radians) + x * sin(radians));
testX = testX + xx +x;
testY = testY + yy +y;
(*current).setX(testX);
(*current).setY(testY);
current++;
}
}
The function is them called like so
list<Shape*>::iterator itr = shapes.begin();
while(itr!=shapes.end())
{
(*itr)->drawShape();
(*itr)->rotate(20);
Console::clear();
(*itr)->drawShape();
itr++;
}
I have revised the code again and can easily manipulate one of the vertices, the issue is when I iterate through the list it does do the other vertices
This allow to manipulate one of the vertices
int x, y, xx, yy;
double radians;
x = centroid.getX();
y = centroid.getY();
x = vertices.back().getX() - centroid.getX();
y = vertices.back().getY() - centroid.getY();
radians = degrees * 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));
once I add the iteration
int x, y, xx, yy;
double radians;
list<Vertex>::iterator itr = vertices.begin();
while (itr != vertices.end())
{
x = centroid.getX();
y = centroid.getY();
x = vertices.back().getX() - centroid.getX();
y = vertices.back().getY() - centroid.getY();
radians = degrees * 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));
itr++;
}
}
I now get no output to the console?
Read the code that you have written, line by line, think about what it does. Think about what is going into each variable, and how it's being used. ESPECIALLY consider how each line of code will affect the OTHER lines of code that are going to execute later.
Compare this with what you think it should be doing. If you don't know what it should be doing, that's what you need to figure out first. Just copy/pasting code in different arrangements and saying it doesn't work is not how programming works.
You should step through it line-by-line in a debugger, watch what it's doing, and see where it isn't doing what you expect it to do.