Here you can find the source of rotatePoint(double x0, double y0, double x, double y, double angle)
Parameter | Description |
---|---|
x0 | center of rotation |
y0 | center of rotation |
x | point to rotate |
y | point to rotate |
angle | angle in radians to rotate, where 0 is right along X axis |
public static Point2D.Double rotatePoint(double x0, double y0, double x, double y, double angle)
//package com.java2s; /*/* w w w . j av a 2 s . c o m*/ MathUtils.java (c) 2012 Edward Swartz All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html */ import java.awt.geom.Point2D; public class Main { /** * Rotate a point relative to screen coordinates, where (0,0) is upper-left. * @param xoffs point to rotate, relative to 0,0 * @param yoffs point to rotate, relative to 0,0 * @param cosA cos(angle) to rotate, where 0 is right along X axis * @param sinA cos(angle) to rotate, where 0 is right along X axis * @return */ public static Point2D.Double rotatePoint(double xoffs, double yoffs, double cosA, double sinA) { double xp = (cosA * (xoffs)) + (-sinA * (yoffs)); double yp = (sinA * (xoffs)) + (cosA * (yoffs)); return new Point2D.Double(xp, yp); } /** * Rotate a point relative to screen coordinates, where (0,0) is upper-left. * * @param x0 center of rotation * @param y0 center of rotation * @param x point to rotate * @param y point to rotate * @param angle angle in radians to rotate, where 0 is right along X axis * @return */ public static Point2D.Double rotatePoint(double x0, double y0, double x, double y, double angle) { Point2D.Double pt = rotatePoint(x, y, Math.cos(angle), Math.sin(angle)); pt.x += x0; pt.y += y0; return pt; } }