Bluebit Software
Bluebit Software Support Forum
 Home          Members     Calendar     Who's On

Welcome Guest ( Login | Register )
        



2D-rotation functions ? Expand / Collapse
Message
Posted Friday, June 17, 2005 1:53 PM Post #64
 

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie
Hi again :-)

My next problem is to rotate as fast as possible a 512 square matrix, around its center,
for a given angle.

After some attempts using cosinus and for...next loops, I wonder if something easier and
faster exists in native bluebit functions ?

Thx for any idea about ...

el doud
Posted Saturday, June 18, 2005 3:15 AM Post #225
 

Bluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit Support

Hi el doud,

Did you try using the RotateTransform method of the System.Drawing.Graphics object? That is part of the .NET Framework.

In case you need to have your image data in Matrix object, the problem here is that you don't need to calculate new values for the data itself but new locations (x,y coordinates) for the data. If there will be a fixed number of rotation angles (eg every 5 degrees) you can precalculate the new locations and then move every pixel to its new location without recalculating.

Another alternative:

Create a 3 column matrix containing the x,y locations of every pixel in the original image:

Matrix A =
0 0 1
0 1 1
0 2 1
0 3 1
0 4 1
...
...
0 511 1
1 0 1
1 1 1
1 2 1
1 3 1
...
...
511 509 1
511 510 1
511 511 1


Multiply this matrix by a 3x3 transformation matrix. The resulted matrix will contain the new locations of every pixel in the rotated image.

There are many articles online of how to calculate the transformation matrix but here is what I can remember:

In order to rotate around the (0,0) point the transormation matrix will be:

Matrix B =
| cos(theta) sin(theta) 0 |
|-sin(theta) cos(theta) 0 |
| 0 0 1 |


"theta" above is the angle of rotation. In order to rotate around any other arbitary point (x,y) first transform the coordinates of the first matrix by multiply by this transformation matrix:

Matrix C =
| 1 0 0 |
| 0 1 0 |
|-x -y 1 |

At the end move all points to their original coordinates by multiplying by D:

Matrix D =
| 1 0 0 |
| 0 1 0 |
| x y 1 |


So the final result will be R = A*C*B*D. In order to save computation time first calculate E=(C*B*D) and then multiply by E. R = A*E.

Please note that the matrix R will contain not image data itself but the positions where the image data should be moved to.

Matrices A, C and D will be always the same and have to be created just once. Matrix B will be created for every rotation angle. It will be very fast to compute matrix E since the matrices C,B,D are very small (3x3). The only operation that will count in timings will be that of A*E.

Please let me know how it works.




Trifon Triantafillidis

Lead Developer

Bluebit Software

« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Trifon

Permissions Expand / Collapse

All times are GMT -5:00, Time now is 6:56am

Powered by InstantForum.NET v4.1.4 © 2012
Execution: 0.266. 9 queries. Compression Disabled.
.NET Matrix Library