2D Matrix Rotation


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2003
    Posts
    985

    Default 2D Matrix Rotation

    Hi Guys,
    Does anyone have a 2D matrix rotation algo they'd like to share?
    I'd like to rotate all bits in a byte array so:

    byte0: 00001110
    byte1: 00001111
    byte2: 00001111
    byte3: 11111111
    byte4: 11111111
    byte5: 00001111
    byte6: 00001111
    byte7: 00001110

    becomes:

    byte0: 01111110
    byte1: 11111111
    byte2: 11111111
    byte3: 11111111
    byte4: 00011000
    byte5: 00011000
    byte6: 00011000
    byte7: 00011000

    I can do this if I have a list of coordinates like this:
    x_new = y_old
    y_new = 1 - (x_old - (8 - 2))
    Do this for every coordinate (64 times) and the result is what I want.
    Art.

  2. #2
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    off the top of my head this is what i came up with (untested):

    Code:
    array          var byte[8]
    array_rotated  var byte[8]
    bit_num        var byte
    byte_num       var byte
    temp           var byte
    result         var byte
    
    for byte_num=0 to 7
        for bit_num=0 to 7
            temp=array[7-bit_num]
            temp=temp>>byte_num
            result=result<<1
            result.0=temp.0
        next bit_num
        array_rotated[byte_num]=result
    next byte_num
    *edit* fixed some mistakes
    *edit* fixed one last mistake
    Last edited by Kamikaze47; - 15th February 2010 at 07:05.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  3. #3
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    I did come up with a way using a very verbose drawn out method that referenced every bit,
    and copies one array to the other, but this looks much neater I'll give it a try, thanks!

  4. #4
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    If it works, you can repay me by sending me some of those DSE component racks you were bragging about on OCAU. Hehe j/k.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  5. #5
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    It's a small world

    There was a little more to it than bragging.
    I was trying to find interested people to get together to possibly buy the next lot in a few months.
    But I also try to show off a bit
    Cheers, Art.

  6. #6
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    *wonders if any of the Perth DSE stores are willing to flog theirs off too*

    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,121


    Did you find this post helpful? Yes | No

    Default

    Nice routine. How about an angle turn and not exactly 90 degrees?

    I mean, to rotate an object live?

    Ioannis

  8. #8
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ioannis View Post
    Nice routine. How about an angle turn and not exactly 90 degrees?

    I mean, to rotate an object live?

    Ioannis
    Then you'd be needing this:
    http://www.picbasic.co.uk/forum/showthread.php?t=10528
    For the trig functions.

  9. #9
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,121


    Did you find this post helpful? Yes | No

    Default

    Ooh, yes. I think I would.

    Thanks a lot.
    Ioannis

Similar Threads

  1. led matrix pic 16f84 and 4017 help me please
    By Mus.me in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 5th February 2011, 00:06
  2. RGB LED Matrix
    By ERIK in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 28th June 2008, 07:01
  3. LED Matrix Question
    By mekohler in forum Schematics
    Replies: 28
    Last Post: - 29th September 2007, 13:12
  4. 4x16 Dot Matrix LCD control is possible?
    By muskut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 1st September 2005, 09:56
  5. need help with switch matrix
    By Srigopal007 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 26th January 2005, 18:59

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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