Java Graphics Rotate rotatePoint(double x0, double y0, double x, double y, double a)

Here you can find the source of rotatePoint(double x0, double y0, double x, double y, double a)

Description

Turn of a point round other point counter-clockwise

License

Apache License

Parameter

Parameter Description
x0 coordinate x central point
y0 coordinate y central point
x coordinate x source point
y coordinate y source point
a angle of rotation in radians

Return

result point

Declaration

public static Point2D.Double rotatePoint(double x0, double y0, double x, double y, double a) 

Method Source Code

//package com.java2s;
/*/*from   w w w .  java  2s .c  o m*/
 * Created on 01.02.2005
 *
 * JDBReport Generator
 * 
 * Copyright (C) 2005-2014 Andrey Kholmanskih
 * 
 * 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.
 *
 */

import java.awt.geom.Point2D;

public class Main {
    /**
     * Turn of a point round other point counter-clockwise
     *
     * @param x0 coordinate x central point
     * @param y0 coordinate y central point
     * @param x coordinate x source point
     * @param y coordinate y source point
     * @param a angle of rotation in radians
     * @return result point
     */
    public static Point2D.Double rotatePoint(double x0, double y0, double x, double y, double a) {
        Point2D.Double p = new Point2D.Double();
        double sina = Math.sin(a);
        double cosa = Math.cos(a);

        p.x = x0 + (x - x0) * cosa + (y0 - y) * sina;
        p.y = y0 + (x - x0) * sina + (y - y0) * cosa;
        return p;
    }
}

Related

  1. rotateCoor(float x, float y, float theta)
  2. rotateCoorAroundPoint(float x, float y, float xctr, float yctr, float theta)
  3. rotateHue(Color color, float fraction)
  4. rotateHue(Color color, float fraction)
  5. rotateMoveClockwise(Point move, int size)
  6. rotatePoint(double x0, double y0, double x, double y, double angle)
  7. rotatePoint(int x, int y, int xC, int yC, float angle)
  8. rotatePoint(Point center, Point p, double angle)
  9. rotatePoint(Point point, Point centerPoint, double angle)