-1

Possible Duplicate:
Rotate Image .pbm Haskell

i need help about a rotation matrix in haskell

i have 2 data type:

data RGBdata= RGB Int Int Int
data PBMfile= PBM Int Int [[RGBdata]]

and my function receive:

spin :: PBMfile -> PBMfile
spin (PBM x y l) = (PBM x y ((transpose . reverse) l))

where 'x' and 'y' is the number of colums and rows respectively (maybe can help to do the function).

for example:

(PBM 2 2 [[(RGB 0 255 255),(RGB 255 0 0)],[(RGB 255 255 255),(RGB 255 0 0)]])

I try rotate 90° to the left using combinations with reverse and transpose, but the image result is wrong.

i try

spin :: PBMfile -> PBMfile
spin (PBM x y l) = (PBM x y ((reverse . transpose) l))

and

spin :: PBMfile -> PBMfile
spin (PBM x y l) = (PBM x y ((transpose . reverse) l))

and

spin :: PBMfile -> PBMfile
spin (PBM x y l) = (PBM x y (((map reverse) . transpose) l))

to rotate the matrix but does not work.

the result is something like

http://imageshack.us/photo/my-images/52/catmc.jpg/

Community
  • 1
  • 1
user495943
  • 13
  • 3
  • "the image result is wrong"... but wrong in what way? Try phrasing your question in the form "I did X, expecting Y, but Z happened instead.". – Daniel Wagner May 02 '12 at 06:42
  • i add explication, to help us to understand – user495943 May 02 '12 at 06:50
  • Not only for us to understand, but also for you to test your functions. What is the result of applying kunwoo32's solution to your own example? – Hans Lub May 02 '12 at 09:07

2 Answers2

2

The transpose operation should happen before the reverse operation. Try

spin (PBM x y l) = (PBM y x ((reverse . transpose) l))

Also the dimensions of the rotated images are switched.

dave4420
  • 46,404
  • 6
  • 118
  • 152
kunwoo32
  • 61
  • 2
1

You need to also consider (map reverse), not just transpose and reverse. I think ((map reverse) . transpose) does what you want.

Chris Kuklewicz
  • 8,123
  • 22
  • 33