Java Graphics Rotate rotate(Point2D.Double point, double dAngle)

Here you can find the source of rotate(Point2D.Double point, double dAngle)

Description

Returns a point that is a copy of the provided point rotated about the origin by a specified amount.

License

Apache License

Parameter

Parameter Description
point the input point
dAngle the amount of angle change

Return

a new point

Declaration

public static Point2D.Double rotate(Point2D.Double point, double dAngle) 

Method Source Code


//package com.java2s;
/*/* w  ww  .j a v a  2 s.  c  om*/
 * #%L
 * BlaiseMath
 * --
 * Copyright (C) 2009 - 2015 Elisha Peterson
 * --
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import java.awt.geom.Point2D;
import static java.lang.Math.*;

public class Main {
    /**
     * Returns a point that is a copy of the provided point rotated about the origin by a specified amount.
     * @param point the input point
     * @param dAngle the amount of angle change
     * @return a new point
     */
    public static Point2D.Double rotate(Point2D.Double point, double dAngle) {
        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);
    }

    /**
     * Returns a point that is a copy of the provided point rotated about the specified anchor by a specified amount.
     * @param anchor the anchor point for the rotation
     * @param point the input point
     * @param dAngle the amount of (counter-clockwise) angle change
     * @return a new point
     */
    public static Point2D.Double rotate(Point2D.Double anchor, Point2D.Double point, double dAngle) {
        double newX = anchor.x + cos(dAngle) * (point.x - anchor.x) - sin(dAngle) * (point.y - anchor.y);
        double newY = anchor.y + sin(dAngle) * (point.x - anchor.x) + cos(dAngle) * (point.y - anchor.y);
        return new Point2D.Double(newX, newY);
    }
}

Related

  1. rotate(Dimension rect)
  2. rotate(final Point2D pos, final Point2D center, final double dist)
  3. rotate(final Point2D vec, final double theta)
  4. rotate(Point p, double angle)
  5. rotate(Point toRotate, float tetta)
  6. rotate(Shape shape, float angle, float x, float y)
  7. rotate_point(double rx, double ry, double angle, double cx, double cy)
  8. rotateArea(Area a, double rotation, Point2D rotateAround)
  9. rotateBy(Vector points, double theta, Vector newPoints)