Here you can find the source of rotateRAD(double x, double y, double a)
Parameter | Description |
---|---|
x | the x coordinate |
y | the y coordinate |
a | the angle (in radians) |
@CheckReturnValue public static Point2D rotateRAD(double x, double y, double a)
//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()); } }