Java Graphics Rotate rotateRAD(double x, double y, double a)

Here you can find the source of rotateRAD(double x, double y, double a)

Description

rotate x and y coordinates (by radians)

License

Open Source License

Parameter

Parameter Description
x the x coordinate
y the y coordinate
a the angle (in radians)

Return

the point rotated by the angle

Declaration

@CheckReturnValue
public static Point2D rotateRAD(double x, double y, double a) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.geom.Point2D;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;

public class Main {
    /**//from   w w w. ja  v a  2 s .  c o  m
     * rotate x and y coordinates (by radians)
     *
     * @param x the x coordinate
     * @param y the y coordinate
     * @param a the angle (in radians)
     * @return the point rotated by the angle
     */
    @CheckReturnValue
    public static Point2D rotateRAD(double x, double y, double a) {
        double cosA = Math.cos(a), sinA = Math.sin(a);
        return new Point2D.Double(cosA * x - sinA * y, sinA * x + cosA * y);
    }

    /**
     * rotate a point (by radians)
     *
     * @param p the point
     * @param a the angle (in radians)
     * @return the point rotated by the angle
     */
    @CheckReturnValue
    public static Point2D rotateRAD(@Nonnull Point2D p, double a) {
        return rotateRAD(p.getX(), p.getY(), a);
    }

    /**
     * rotate a point around another point (by radians)
     *
     * @param p    the point being rotated
     * @param c    the point its being rotated around
     * @param aRAD the angle (in radians)
     * @return the point rotated by the angle
     */
    @CheckReturnValue
    public static Point2D rotateRAD(@Nonnull Point2D p, @Nonnull Point2D c, double aRAD) {
        return add(c, rotateRAD(subtract(p, c), aRAD));
    }

    /**
     * add two points
     *
     * @param pA the first point
     * @param pB the second point
     * @return the sum of the two points
     */
    @CheckReturnValue
    public static Point2D add(@Nonnull Point2D pA, @Nonnull Point2D pB) {
        return new Point2D.Double(pA.getX() + pB.getX(), pA.getY() + pB.getY());
    }

    /**
     * subtract two points
     *
     * @param pA the first point
     * @param pB the second point
     * @return the difference of the two points
     */
    @CheckReturnValue
    public static Point2D subtract(@Nonnull Point2D pA, @Nonnull Point2D pB) {
        return new Point2D.Double(pA.getX() - pB.getX(), pA.getY() - pB.getY());
    }
}

Related

  1. rotatePoint(Point center, Point p, double angle)
  2. rotatePoint(Point point, Point centerPoint, double angle)
  3. rotatePoint(Point reference, Point toRotate, int degrees)
  4. rotatePoint(Point target, Point origin, double theta)
  5. rotatePoint2D(final Point aPoint, final float aDeg)
  6. rotateShape(final Shape base, final double angle, final float x, final float y)
  7. rotateToZero(Vector points, Vector newPoints)