I have a shape e-g, Rectanle and i want to rotate it at an angle X and want to get the updated rotated points of shape.
Currently for rotation of object i am using canvas.rotate, but the original points remains the same; not the rotated one. I am using this code.
canvas.save();
canvas.rotate(angle, Pivate.x, Pivate.y);
canvas.drawRect(left, top, right, bottom, redPaint);
canvas.restore();
Any help will be appreciated...
The rotate() method allows you to rotate a drawing object on the canvas. The rotate() method accepts a rotation angle in radians. If the angle is positive, the rotation is clockwise. In case the angle is negative, the rotation is counterclockwise.
When a point (x,y) is rotated about the origin (0,0) counterclockwise by an angle θ, the coordinates of the new point (x′,y′) are x′=xcos(θ)−ysin(θ),y′=xsin(θ)+ycos(θ).
Coordinates of Rotation: The point (x,y) rotated an angle of θ counter-clockwise about the origin will land at point (x′,y′) where x′=xcos(θ)−ysin(θ) x ′ = x cos ( θ ) − y sin and y′=ycos(θ)+xsin(θ) y ′ = y cos ( θ ) + x sin .
You need the following way to get update array of points...
float[] ptArr = new float[] { 20, 30, 60, 30, 60, 45, 20, 45};
Matrix m = new Matrix();
m.preRotate(angle, px, py); // where px and py is pivot point.
m.mapPoints(ptArr);
//at this point your array will be updated.
canvas.drawPoints(ptArr, mPaint);
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