Get the new point in a circle if the given point is rotated by an angle - Android java.lang

Android examples for java.lang:Math Trigonometric Function

Description

Get the new point in a circle if the given point is rotated by an angle

Demo Code

/*******************************************************************************
 * Copyright (c) 2011 MadRobot.//from   w w  w .j a v  a2 s  .  c  o  m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *  Elton Kent - initial API and implementation
 ******************************************************************************/
//package com.java2s;
import android.graphics.PointF;

public class Main {
    /**
     * 
     * Get the new point in a circle if the given <code>point</code> is rotated
     * by an <code>angle</code>
     * 
     * @param point
     *            to be rotated
     * @param center
     *            of the circle
     * @param angle
     *            the point should be rotated by
     * @return The new point after rotation
     */
    public static PointF getRotatedPoint(PointF point, PointF center,
            float angle) {
        PointF newPoint = new PointF();
        float centerX = point.x - center.x;
        float centerY = point.y - center.y;
        newPoint.x = (float) (Math.cos(angle) * (centerX) - Math.sin(angle)
                * (centerY) + center.x);
        newPoint.y = (float) (Math.sin(angle) * (centerX) + Math.cos(angle)
                * (centerY) + center.y);
        return newPoint;
    }
}

Related Tutorials