matrixbase::Rotate

Description

Rotates the matrix counter-clockwize by the specified angle.

Syntax

BOOL Rotate( int nAngleDegree = 90 )

Parameters

nAngleDegree
[input] The rotation angle in degrees, can be negative but must be a multiple
of 90 otherwise the closest multiple is used

Return

Returns TRUE on success or FALSE on failure.

Examples

EX1

void matrixbase_Rotate_ex1()
{
    BOOL rc;

    matrix<double> mat1 = {
        {1,  2,  3,  4},
        {2,  4,  6,  8},
        {3,  6,  9, 12}
    };
    MatrixPage MatPg1;
    MatPg1.Create("Origin");
    MatrixLayer MatLy1 = MatPg1.Layers(0);
    Matrix Mat1(MatLy1);
    Mat1 = mat1;
    printf("  The original matrix is %s.\n",Mat1.GetName());
    
    matrix mat2(mat1);  // Create mat2, and copy mat1 to mat2
    rc=mat2.Rotate(90); // Demonstrate  Rotate +90 degree
    // Result matrix:
    //    {4,  8,  12},
    //    {3,  6,   9},
    //    {2,  4,   6},
    //    {1,  2,   3}
        
    if(!rc) printf("Error: Rotate(90) on a matrix failed.\n");
    else
    {
        MatrixPage MatPg2;
        MatPg2.Create("Origin");
        MatrixLayer MatLy2 = MatPg2.Layers(0);
        Matrix Mat2(MatLy2);
        Mat2 = mat2;
        printf("  Observe the 90degree-rotated (counter-clockwize) matrix in %s.\n",
          Mat2.GetName());
    }

    matrix mat3(mat1);  // Create mat3, and copy mat1 to mat3
    rc=mat3.Rotate(-90); // Demonstrate Rotate -90 degree
    // Result matrix:
    //    { 3,  2,  1},
    //    { 6,  3,  2},
    //    { 9,  6,  3},
    //    {12,  8,  4}
    
    if(!rc) printf("Error: Rotate(-90) on a matrix failed.\n");
    else
    {
        MatrixPage MatPg3;
        MatPg3.Create("Origin");
        MatrixLayer MatLy3 = MatPg3.Layers(0);
        Matrix Mat3(MatLy3);
        Mat3 = mat3;
        printf("  Observe the -90degree-rotated (clockwize) matrix in %s.\n",
          Mat3.GetName());
    }


}

Remark

Rotates the matrix counter-clockwize by the specified angle. Angles must be multiples of 90 degrees but can be negative. Rotating a matrix by 90 degrees has the simultaneous effect of making the first row become the first column in reverse order, and the last column becomes the first row. By -90 degrees, the last row becomes the first column, and the first column becomes the first row in reverse order.

See Also

matrixbase::FlipHorizontal, matrixbase::FlipVertical, matrixbase::Reorder, matrixbase::Transpose

header to Include

origin.h