Skip to content
Advertisement

How to rotate an array counter clockwise and invert it vertically?

Say each pixel in this picture(fig 1) is an element in an array. How would I rotate it 90 degress counter-clockwise(fig 2) and invert it vertically(fig 3)?

figure 1: fig 1

figure 2: fig 2

figure 3: enter image description here

My current codes are:

JavaScript

The invert does the same function as the rotate though. Any help?

Advertisement

Answer

seems like you are trying to transpose the array (fig3 = transpose(fig1)).

use a double for loop and save in the entry [i][j] the value of [j][i].

see LINK for more information on the matrix transpose…

so all in all, you can use transpose to get fig3 and afterwards invert to get fig2.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement