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

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

Description

Rotate a point relative to screen coordinates, where (0,0) is upper-left.

License

Open Source License

Parameter

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

Declaration

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

Method Source Code

//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;
    }
}

Related

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