Java AffineTransform rotate(double angle, double oldAngle, Point.Double point)

PreviousNext

//package com.java2s;
import java.awt.*;
import java.awt.geom.AffineTransform;

public class Main {
    public static Point.Double rotate(double angle, double oldAngle, Point.Double point) {

        double[][] matrix = { { Math.cos(angle - oldAngle), -Math.sin(angle - oldAngle) },
                { Math.sin(angle - oldAngle), Math.cos(angle - oldAngle) } };

        return matrixMultiply(matrix, point);
    }//   w  w   w .  d e    m o  2  s  . c   o m  

    public static Shape rotate(double angle, Shape shape) {
        shape = AffineTransform.getRotateInstance(angle).createTransformedShape(shape);
        return shape;
    }

    public static Point.Double matrixMultiply(double[][] matrix, Point.Double point) {

        double x = matrix[0][0] * point.x + matrix[0][1] * point.y;
        double y = matrix[1][0] * point.x + matrix[1][1] * point.y;
        return new Point.Double(x, y);
    }
}
PreviousNext

Related