Java Graphics Rotate rotateCoor(float x, float y, float theta)

Here you can find the source of rotateCoor(float x, float y, float theta)

Description

rotates a point theta radians, returns a new point rotation is counterclockwise for positive theta in Cartesian system, clockwise in screen display coordinate system

License

Open Source License

Parameter

Parameter Description
x x coordinate of point
y y coordinate of point
theta angle to rotate, in radians

Return

a new point

Declaration

public static Point2D.Float rotateCoor(float x, float y, float theta) 

Method Source Code


//package com.java2s;
/*/*from   w w w .j a  va2  s .  c o  m*/
 * Copyright (c) 2011, Paul Hertz This library is free software; you can
 * redistribute it and/or modify it under the terms of the GNU Lesser General
 * Public License as published by the Free Software Foundation; either version
 * 3.0 of the License, or (at your option) any later version.
 * http://www.gnu.org/licenses/lgpl.html This library 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 Lesser General Public License for more details. You should have
 * received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
 * Fifth Floor, Boston, MA 02110-1301, USA
 * 
 * @author      ##author##
 * @modified   ##date##
 * @version      ##version##
 * 
 */

import java.awt.geom.*;

public class Main {
    /**
     * rotates a point theta radians, returns a new point
     * rotation is counterclockwise for positive theta in Cartesian system, 
     * clockwise in screen display coordinate system
     * @param x       x coordinate of point
     * @param y       y coordinate of point
     * @param theta   angle to rotate, in radians
     * @return        a new point
     */
    public static Point2D.Float rotateCoor(float x, float y, float theta) {
        double sintheta = Math.sin(theta);
        double costheta = Math.cos(theta);
        return new Point2D.Float((float) (x * costheta - y * sintheta), (float) (x * sintheta + y * costheta));
    }

    public static Point2D.Double rotateCoor(double x, double y, double theta) {
        double sintheta = Math.sin(theta);
        double costheta = Math.cos(theta);
        return new Point2D.Double((x * costheta - y * sintheta), (x * sintheta + y * costheta));
    }

    /**
     * rotates a point theta radians, modifies and returns the point
     * rotation is counterclockwise for positive theta in Cartesian system, 
     * clockwise in screen display coordinate system
     * @param pt      the point to rotate
     * @param theta   angle to rotate, in radians
     * @return        the rotated point
     */
    public static Point2D.Float rotateCoor(Point2D.Float pt, float theta) {
        // Rotate vector or point (x,y) through an angle theta
        // degrees in radians, rotation is counterclockwise from the coordinate axis
        // modifies and returns same point
        double sintheta = Math.sin(theta);
        double costheta = Math.cos(theta);
        pt.setLocation((pt.x * costheta - pt.y * sintheta), (pt.x * sintheta + pt.y * costheta));
        return pt;
    }

    public static Point2D.Double rotateCoor(Point2D.Double pt, double theta) {
        // Rotate vector or point (x,y) through an angle theta
        // degrees in radians, rotation is counterclockwise from the coordinate axis
        // modifies and returns same point
        double sintheta = Math.sin(theta);
        double costheta = Math.cos(theta);
        pt.setLocation((pt.x * costheta - pt.y * sintheta), (pt.x * sintheta + pt.y * costheta));
        return pt;
    }
}

Related

  1. rotate_point(double rx, double ry, double angle, double cx, double cy)
  2. rotateArea(Area a, double rotation, Point2D rotateAround)
  3. rotateBy(Vector points, double theta, Vector newPoints)
  4. rotateByAngle(final Point2D pos, final Point2D center, final double angle)
  5. rotateClockwise(Path source, Path target)
  6. rotateCoorAroundPoint(float x, float y, float xctr, float yctr, float theta)
  7. rotateHue(Color color, float fraction)
  8. rotateHue(Color color, float fraction)
  9. rotateMoveClockwise(Point move, int size)