I am struggling with a spin of 6 points. These points rotate around a central point in the middle. But what happens is that the shape region shrinks and becomes smaller and smaller.
The form is drawn on JPanel using PaintComponent. This means that the canvas only supports integer positioning, although I can store positions in doubles.
I use Point2D.Double to store the position of the points. I Turn all the points 1 deagre on each function call
I think my understanding of rotation is not enough, I can rotate 360 โโdeegre in one call or 180, this works fine. But 45 deegres or 90 will completely rotate my points in a line (picture below).
This problem bothered me for a while, but, as always, I'm sure there is a simple solution.
Here is the rotation function
@Override public synchronized void rotatePoints(int move_x, int move_y) { // TODO Auto-generated method stub super.rotatePoints(move_x, move_y); BottomPanel.appendText("Area of Polygon is: " + UtilClass.calculateAreaOfPolygon(points)+ "\n"); double degrees=1.0; double radians = degrees * (double)(Math.PI / 180.0); //GET THE CENTER POINT C Point2D.Double center = UtilClass.getCenterOfPolygon(points); //ITERATE THROUGH THE POINTS Iterator<PointClass> itr = points.iterator(); while(itr.hasNext()) { //GET THE POINT PointClass point_class = itr.next(); //point_class = points.get(3); //FIRST TRANSLATE THE DIFFERENCE double x1 = point_class.point.x - center.x; double y1 = point_class.point.y - center.y; //APPLY ROTATION MATRIX x1 = (x1 * Math.cos(radians)) - (y1 * Math.sin(radians)); y1 = (x1 * Math.sin(radians)) + (y1 * Math.cos(radians)); //TRANSLATE BACK point_class.point.setLocation(x1 + center.x, y1 + center.y); //ADD THE DEEGRES TO POINT CLASS point_class.angle += Math.toDegrees(radians); } }
Here is the code to restore the central location of a given polygon
public synchronized static Point2D.Double getCenterOfPolygon(List<PointClass> points) {
Here is an image of a shape that rotates all its points 1 degree clockwise

After each rotation, I print the polygon area here is the result
- Polygon Area: 6290
- Polygon Area: 6288
- Polygon Area: 6286
- Polygon Area: 6284
- Polygon Area: 6283
- Polygon Area: 6281
Here is an image of a shape that rotates all its points 90 degrees clockwise after one call. He does not want to do this.
I would be happy for any suggestions or advice.
