Reputation: 2811
I searched on internet and I saw lots of posts about how to rotate a matrix or an image by 90 or 180 degrees.But how can I rotate a matrix with 12 degrees or 162 degrees?
From:
To:
This image is rotated with ~35 degrees.
As you can see my matrix is the horse image and the circle is the rotation path, and the big rectangle is the new matrix created after rotation.
How can i achieve this? Thanks!
PS: This does not work
int angle=35*Math.PI/180;
int x1 = (int)(x * cos(angle)) - (y * sin(angle));
int y1 = (int)(y * cos(angle)) + (x * sin(angle));
Upvotes: 0
Views: 1598
Reputation: 4795
Maybe your code would work if you saved x value before using it to compute y.
35*PI/180
float angle = 35*Math.PI/180;
int x1 = round(x * cos(angle) - y * sin(angle));
int y1 = round(y * cos(angle) + x * sin(angle));
Note: casting is huggly.
Upvotes: 2