# Thread: Rotation 90 degrees to right Help

1. Senior Member
Join Date
Mar 2013
Posts
120
Rep Power
0

## Rotation 90 degrees to right Help

Hello
I need help rotating a pic 90 degrees to the right

Java Code:
```   Photograph rotated_photo = new Photograph(photo.getWidth(), photo.getHeight());

for (int col = 0; col < photo.getHeight(); col ++){
for (int row = 0; row < photo.getWidth(); row ++){

Pixel p = photo.getPixel(row, col);
rotated_photo.setPixel(???, ???, p);       //Please give me hint on how to do this
}
}

return rotated_photo;```

2. Senior Member
Join Date
Jun 2007
Location
Bali, Indonesia
Posts
753
Rep Power
7

## Re: Rotation 90 degrees to right Help

Part of what library / API is the Photograph class?

3. Senior Member
Join Date
Mar 2013
Posts
120
Rep Power
0

## Re: Rotation 90 degrees to right Help

Part of what library / API is the Photograph class?
The Photograph and Pixel Class is a custom classes created by my professor.
-------------------------------------------------------------------

4. Senior Member
Join Date
Mar 2013
Posts
120
Rep Power
0

## Re: Rotation 90 degrees to right Help

I need help on the math. I'm not getting it.

My objective is to take an image and rotate 90 degrees to the right.

So given an image with letters as pixels:

abcd
efgh
i j k l
mnop

(becomes this after rotation)

m i e a
n j f b
o k g c
p l h d

----

So I create a new photo image

Create a nested for loop to go through each row and col

Find the pixel in each row and column

and the set the pixel to the new photo

------

so I have (psuedo-code)

Photograph rotate = new Photo (getwidth, getheight);

for ( row = 0; row < width ; row ++)
for (col = 0; col < height ; col ++0

get pixel (row, col)

rotate.setPixel ( ????? , ???? , pixel)

----

I need help on what to fill in for the "????"
I drew it out and I know when rotated, row becomes col and vise versa...
Im just not getting it.

5. ## Re: Rotation 90 degrees to right Help

Suppose there are R rows and C columns; for matrix coordinate [y,x] (row, column) the rotated coordinates are [x, R-y-1].

kind regards,

Jos

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•