Rotates a point a given angle around the center. - Java java.lang

Java examples for java.lang:Math Geometry

Description

Rotates a point a given angle around the center.

Demo Code


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

import java.awt.geom.Point2D;

public class Main {
    /**//from w w w  .ja va2s  . com
     * Rotates a point a given angle around the center.
     * 
     * @param pos The point to rotate.
     * @param center The center.
     * @param angle The angle.
     * @return The rotated point.
     */
    public static Point2D rotateByAngle(final Point2D pos,
            final Point2D center, final double angle) {
        final AffineTransform at = AffineTransform.getRotateInstance(angle,
                center.getX(), center.getY());
        return at.transform(pos, null);
    }
}

Related Tutorials