mathnet-numerics
mathnet-numerics copied to clipboard
Hot to rotate a matrix?
Please excuse the beginner question, but how to rotate a DenseMatrix in steps of 90 degrees?
It is my understanding that what you are asking is as follows:
you have a data point with coordinates in the x-y plane, and want to determine (calculate) the new coordinates after a rotation is applied to said data point.
If that is what you are asking, the fact is that such types of rotations are linear transforms of the kind that can be modeled with Matrix Algebra.
Since these kinds of rotations can be easily obtained with basic operations of matrices and vectors with MathNet Numerics, there is no value to include a specific method in this library to solve such a problem.
The calculation to do is represented in the image in the following link: https://wikimedia.org/api/rest_v1/media/math/render/svg/50622f9a4a7ba2961f5df5f7e0882983cf2f1d2f
Kind regards, GEN
@gaston-e-nusimovich: As you seem to know how to turn a Matrix 90 or 180 degrees with Math.NET numerics, could you maybe give us a hint how to actually do it? Thanks!
I was hoping this package would have a built-in solution, but I guess not. Gaston was hinting at using standard rotation matrices. He links to an image of a matrix to rotate a 2D vector. These are the ones you need for a 3D vector/matrix:
https://wikimedia.org/api/rest_v1/media/math/render/svg/a6821937d5031de282a190f75312353c970aa2df
At 90 and 180 degrees, the angles all become zero or one.
Had to do it myself((((
static Matrix<Complex> RotateMatrixAntiClockwise(Matrix<Complex> oldMatrix)
{
Matrix<Complex> newMatrix = Matrix<Complex>.Build.Dense(oldMatrix.RowCount, oldMatrix.ColumnCount);
int newColumn;
int newRow = 0;
for(int oldColumn = 0; oldColumn < oldMatrix.ColumnCount - 1; oldColumn++)
{
newColumn = 0;
for(int oldRow = oldMatrix.RowCount; oldRow >= 0; oldRow--)
{
newMatrix[newRow, newColumn] = oldMatrix[oldRow, oldColumn];
newColumn++;
}
newRow++;
}
return newMatrix;
}
I would go as far as to suggest that we introduced to the package the special orthogonal group.
Then we can easily rotate around any arbitrary axis so the rotations by +/-90 or +/-180 are trivial cases of the general formulation.
The main drawback is that this approach makes sense only in 3D, so I’m not sure this really belongs here, since this can be seen as a general linear algebra package.
Feedback anyone?