Here you can find the source of rotate(Point2D.Double point, double dAngle)
Parameter | Description |
---|---|
point | the input point |
dAngle | the amount of angle change |
public static Point2D.Double rotate(Point2D.Double point, double dAngle)
//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); } }