rotate Rect - Android Graphics

Android examples for Graphics:Rectangle

Description

rotate Rect

Demo Code


//package com.java2s;
import android.graphics.RectF;

public class Main {

    public static void rotateRect(RectF rect, float center_x,
            float center_y, float roatetAngle) {
        float x = rect.centerX();
        float y = rect.centerY();
        float sinA = (float) Math.sin(Math.toRadians(roatetAngle));
        float cosA = (float) Math.cos(Math.toRadians(roatetAngle));
        float newX = center_x + (x - center_x) * cosA - (y - center_y)
                * sinA;/*from ww w.  java2s.c  o m*/
        float newY = center_y + (y - center_y) * cosA + (x - center_x)
                * sinA;

        float dx = newX - x;
        float dy = newY - y;

        rect.offset(dx, dy);
    }
}

Related Tutorials