Java Utililty Methods Graphics Rotate

List of utility methods to do Graphics Rotate

Description

The list of methods to do Graphics Rotate are organized into topic(s).

Method

Point2D.DoublerotatePoint(double x0, double y0, double x, double y, double angle)
Rotate a point relative to screen coordinates, where (0,0) is upper-left.
Point2D.Double pt = rotatePoint(x, y, Math.cos(angle), Math.sin(angle));
pt.x += x0;
pt.y += y0;
return pt;
PointrotatePoint(int x, int y, int xC, int yC, float angle)
Rotates a 2-dimensional point with the coordinates x,y arount another point xC,yC with the specified angle.
float rot = (float) Math.toRadians(angle);
double dx = xC + (x - xC) * Math.cos(rot) + (y - yC) * Math.sin(rot);
double dy = yC - (x - xC) * Math.sin(rot) + (y - yC) * Math.cos(rot);
int x_ = (int) dx;
int y_ = (int) dy;
return new Point(x_, y_);
PointrotatePoint(Point center, Point p, double angle)
rotate Point
double[] pt = { p.x, p.y };
AffineTransform.getRotateInstance(Math.toRadians(360 - angle), center.x, center.y).transform(pt, 0, pt, 0,
        1);
return new Point((int) Math.round(pt[0]), (int) Math.round(pt[1]));
voidrotatePoint(Point point, Point centerPoint, double angle)
rotate Point
AffineTransform t = AffineTransform.getRotateInstance(angle, centerPoint.x, centerPoint.y);
t.transform(point, point);
PointrotatePoint(Point reference, Point toRotate, int degrees)
Rotates a point with respect to a center point.
double angle = degrees;
angle = (angle) * (Math.PI / 180);
double rotatedX = Math.cos(angle) * (toRotate.x - reference.x)
        - Math.sin(angle) * (toRotate.y - reference.y) + reference.x;
double rotatedY = Math.sin(angle) * (toRotate.x - reference.x)
        + Math.cos(angle) * (toRotate.y - reference.y) + reference.y;
return new Point((int) rotatedX, (int) rotatedY);
PointrotatePoint(Point target, Point origin, double theta)
_more_
Point ret = rotatePoint(new Point(target.x - origin.x, target.y - origin.y), theta);
ret.x += origin.x;
ret.y += origin.y;
return ret;
PointrotatePoint2D(final Point aPoint, final float aDeg)
rotate Point D
double a = Math.toRadians(aDeg);
Point p = new Point();
p.x = (int) ((aPoint.x * Math.cos(a)) - (aPoint.y * Math.sin(a)));
p.y = (int) ((aPoint.y * Math.cos(a)) + (aPoint.x * Math.sin(a)));
return p;
Point2DrotateRAD(double x, double y, double a)
rotate x and y coordinates (by radians)
double cosA = Math.cos(a), sinA = Math.sin(a);
return new Point2D.Double(cosA * x - sinA * y, sinA * x + cosA * y);
ShaperotateShape(final Shape base, final double angle, final float x, final float y)
Rotates a shape about the specified coordinates.
if (base == null) {
    return null;
final AffineTransform rotate = AffineTransform.getRotateInstance(angle, x, y);
final Shape result = rotate.createTransformedShape(base);
return result;
voidrotateToZero(Vector points, Vector newPoints)
rotate To Zero
Point2D c = centroid(points);
double theta = Math.atan2(c.getY() - points.get(0).getY(), c.getX() - points.get(0).getX());
rotateBy(points, -theta, newPoints);