Here you can find the source of rotatePoint(int x, int y, int xC, int yC, float angle)
Parameter | Description |
---|---|
x | the x-coordinate of the point |
y | the y-coordinate of the point |
xC | the x-coordinate of the rotation center |
yC | the y-coordinate of the rotation center |
angle | the angle of rotation in degrees |
public static Point rotatePoint(int x, int y, int xC, int yC, float angle)
//package com.java2s; /**//from ww w .j a v a 2s. c o m BreadBoard Editor Written and maintained by Matthias Pueski Copyright (c) 2010-2012 Matthias Pueski This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ import java.awt.Point; public class Main { /** * Rotates a 2-dimensional point with the coordinates x,y arount another * point xC,yC with the specified angle. * * @param x the x-coordinate of the point * @param y the y-coordinate of the point * @param xC the x-coordinate of the rotation center * @param yC the y-coordinate of the rotation center * @param angle the angle of rotation in degrees * * @return the rotated {@link Point} */ public static Point rotatePoint(int x, int y, int xC, int yC, float angle) { float rot = (float) Math.toRadians(angle); double dx = xC + (x - xC) * Math.cos(rot) + (y - yC) * Math.sin(rot); double dy = yC - (x - xC) * Math.sin(rot) + (y - yC) * Math.cos(rot); int x_ = (int) dx; int y_ = (int) dy; return new Point(x_, y_); } public static Point rotatePoint(double x, double y, int xC, int yC, float angle) { float rot = (float) Math.toRadians(angle); double dx = xC + (x - xC) * Math.cos(rot) + (y - yC) * Math.sin(rot); double dy = yC - (x - xC) * Math.sin(rot) + (y - yC) * Math.cos(rot); int x_ = (int) dx; int y_ = (int) dy; return new Point(x_, y_); } }