Ok so i have created a Rectangle on a canvas using this code
Rect r =new Rect((point.x - rectWidth / 2), (point.y - rectHeight / 2),(point.x-rectWidth / 2),(point.y + rectHeight / 2));
point being the center of the rectangle determined by a touch event. But now I want to be able to rotate this rectangle. Is there any code or method that will allow the user to rotate a shape about its center. I am also interested in getting the corner points of such a rectangle. Any help is appreciated. Thanks.
To rotate a rectangle around its own center (as opposed to the origin):
Matrix m = new Matrix();
// point is the point about which to rotate.
m.setRotate(degrees, point.x, point.y);
m.mapRect(r);
You can also use Matrix.mapPoints()
to find how the corners are transformed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With