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

voidrotate(AffineTransform transform, float angleInDegrees)
rotate the given transform
if (transform != null) {
    double angleInRadians = angleInDegrees * (Math.PI / 180);
    transform.rotate(angleInRadians);
byte[]rotate(byte[] bytes)
rotate
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BufferedImage src = ImageIO.read(inputStream);
int height = src.getHeight();
AffineTransform transform = AffineTransform.getRotateInstance(Math.toRadians(90), height / 2, height / 2);
AffineTransformOp transformOp = new AffineTransformOp(transform, AffineTransformOp.TYPE_BICUBIC);
BufferedImage dst = new BufferedImage(src.getHeight(), src.getWidth(), src.getType());
transformOp.filter(src, dst);
...
Dimensionrotate(Dimension rect)
Rotates the rectangle by 90 degrees.
return new Dimension(rect.height, rect.width);
Point2Drotate(final Point2D pos, final Point2D center, final double dist)
Rotates a point around the center such that the result has the given distance to the original point.
final double f = dist > 0 ? 1 : -1;
final double dSq = dist * dist;
final Point2D rad = subVec(pos, center);
final double radSq = getLengthSq(rad);
if (dSq > 4 * radSq)
    return subVec(center, rad);
return rotateByAngle(pos, center, f * Math.acos(1 - dSq * 0.5 / radSq));
Point2Drotate(final Point2D vec, final double theta)
Rotates a vector around the origin.
final double cos = Math.cos(-theta);
final double sin = Math.sin(-theta);
final double x = vec.getX();
final double y = vec.getY();
return new Point2D.Double(x * cos - y * sin, x * sin + y * cos);
Pointrotate(Point p, double angle)
rotate
double c = Math.cos(angle);
double s = Math.sin(angle);
return new Point((int) (p.x * c - p.y * s), (int) (p.x * s + p.y * c));
Pointrotate(Point toRotate, float tetta)
rotate
float sin = (float) Math.sin(tetta);
float cos = (float) Math.cos(tetta);
int x = (int) (toRotate.x * cos - toRotate.y * sin);
int y = (int) (toRotate.x * sin + toRotate.y * cos);
return new Point(x, y);
Point2D.Doublerotate(Point2D.Double point, double dAngle)
Returns a point that is a copy of the provided point rotated about the origin by a specified amount.
double newX = cos(dAngle) * point.x - sin(dAngle) * point.y;
double newY = sin(dAngle) * point.x + cos(dAngle) * point.y;
return new Point2D.Double(newX, newY);
Shaperotate(Shape shape, float angle, float x, float y)
rotate
if (angle == 0) {
    return shape;
return AffineTransform.getRotateInstance(Math.toRadians(360 - angle), x, y).createTransformedShape(shape);
Point2D.Doublerotate_point(double rx, double ry, double angle, double cx, double cy)
Rotate point (rx,ry) w.r.t point (cx,cy) by specified angle.
Point2D.Double p = new Point2D.Double(rx, ry);
double s = Math.sin(angle);
double c = Math.cos(angle);
p.x -= cx;
p.y -= cy;
double xnew = p.x * c - p.y * s;
double ynew = p.x * s + p.y * c;
p.x = xnew + cx;
...