Answer the question
In order to leave comments, you need to log in
How to perform Java 2D triangle rotation algorithm?
It is necessary to build a triangle, and when you press the button, it should rotate by 30 degrees. I roughly painted the algorithm for myself, but I can’t implement it.
1) draw 3 points and connect them with lines
2) clear the screen, i.e. paint everything in the background color
3) calculate new coordinates for the given 3 points of the triangle
4) display these points with new coordinates on the screen and connect them with lines
Answer the question
In order to leave comments, you need to log in
So what's the problem? AffineTransform www.java2s.com/Tutorials/Java/Graphics_How_to/Tran...
Coordinates always start from 0. Obviously, you will not draw at the origin. You must decide which point you will rotate the triangle around. Then move this point to the origin of coordinates, and move the vertices of the triangle with the same transformation. Then rotate the points using the rotation matrix. The point around which you rotate will remain at the origin. Then you need to perform a reverse transfer.
They gave you a link to affine transformations, I painted the algorithm for you. It remains to code.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question