Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 26th, 2006, 9:34 AM   #11
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,028
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
Yeah, Andro, that is quite silly. Matrix math should only be used if you're doing transformations of non 90 degree intervals, or reverse transformations. Since the former is impossible to have in a nested list, it's best to stick with inverse functions/linear transformations.
Sane is online now   Reply With Quote
Old Jul 26th, 2006, 1:03 PM   #12
andro
Professional Programmer
 
Join Date: Oct 2005
Location: California
Posts: 316
Rep Power: 4 andro is on a distinguished road
Send a message via AIM to andro
I may not have understood correctly, but..

Rotating about the X axis:

[1, 0, 0]
[0, cos x, -sin x]
[0, sin x, cos x]

Rotating about the Y axis:

[cos x, 0, sin x]
[0, 1, 0]
[-sin x, 0, cos x]

Rotating about Z:

[cos x, -sin x, 0]
[sin x, cos x, 0]
[0, 0, 1]

Although that may or may not do what you want, I haven't touched that stuff in a while now



EDIT: You know I think this applies to transforming actual objects in a 3D coordinate space... not physically rotating a 3x3 matrix in place like you are describing... never mind all of this.
andro is offline   Reply With Quote
Old Jul 26th, 2006, 2:22 PM   #13
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,028
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
Your edit said it all.
Sane is online now   Reply With Quote
Old Jul 27th, 2006, 10:03 AM   #14
hydroxide
Programmer
 
Join Date: Apr 2005
Posts: 73
Rep Power: 4 hydroxide is on a distinguished road
Quote:
Originally Posted by DaWei
What would be your Pythonic solution for rotating a 3x3 grid counterclockwise by 90 degrees?
If you will really be dealing with larger grids (ie: 3*3 is just to get sample code) then you might find NumPy, etc worthwhile - there's a rot90() function which does just that.

If you _are_ using 3*3, you feel numpy is overkill, you need to do this frequently, you need the speed, and you don't want to use one of the reallocating solutions you could just roll your own:
# Modifies a 3*3 list of lists inplace.  No, it's not incredibly pretty.
def rot90(grid):
    r1 = grid[0]
    r2 = grid[1]
    r3 = grid[2]

    (r1[0], r1[1], r1[2], 
     r2[0],        r2[2],
     r3[0], r3[1], r3[2]) =\

        (r3[0], r2[0], r1[0], 
         r3[1],        r1[1],
         r3[2], r2[2], r1[2])
-T.
hydroxide is offline   Reply With Quote
Old Jul 27th, 2006, 5:44 PM   #15
stevengs
Professional Programmer
 
stevengs's Avatar
 
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4 stevengs is on a distinguished road
Quote:
What would be your Pythonic solution for rotating a 3x3 grid counterclockwise by 90 degrees?...

...Why? Example?
hehe, I can't believe that noone has made any mention of "posting your code and showing that you made an effort"

-- I reckon I better duck ... incoming --
__________________
-Steven
"Is this a piece of your brain?" - Basil Fawlty

Last edited by stevengs; Jul 27th, 2006 at 6:00 PM.
stevengs is offline   Reply With Quote
Old Jul 27th, 2006, 5:48 PM   #16
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,028
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
I had assumed in DaWei's case it wasn't a question of inability, but a question of curiousity for the sake of seeing the alternatives. That, or he just wanted another tick on his little side counter there.
Sane is online now   Reply With Quote
Old Jul 27th, 2006, 5:57 PM   #17
stevengs
Professional Programmer
 
stevengs's Avatar
 
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4 stevengs is on a distinguished road
Naaa, it's probably a homework assignment, and we all know the rules about homework assignments..
__________________
-Steven
"Is this a piece of your brain?" - Basil Fawlty
stevengs is offline   Reply With Quote
Old Jul 27th, 2006, 6:04 PM   #18
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,028
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
Hahahahaha. That's excellent. It must definitely be homework.
Sane is online now   Reply With Quote
Old Jul 28th, 2006, 8:58 AM   #19
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Yeah, it's homework. I got an F. Except from Grumpy, who gave me an upside down F, and Narue, who gave me two Fs. I got pissed and moved to Germany, next town over from Steven, Bad Thang.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 28th, 2006, 9:57 AM   #20
stevengs
Professional Programmer
 
stevengs's Avatar
 
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4 stevengs is on a distinguished road
Quote:
Originally Posted by DaWei
...an upside down F...
genial!
Quote:
Originally Posted by DaWei
... Bad Thang.
Well, the beer is good, but since you are a Glenlivet advocat, that wouldn't much make up for the 7$/Gallon at the pumps!
__________________
-Steven
"Is this a piece of your brain?" - Basil Fawlty
stevengs is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Python] Grid encryptor Jessehk Show Off Your Open Source Projects 7 Nov 29th, 2007 8:11 PM
Distance between 2 grid references Oddball Show Off Your Open Source Projects 7 Mar 12th, 2006 3:52 PM
easiest way to represent a grid? keweedsmo C++ 4 Feb 10th, 2006 7:03 PM
Little off-topic... Grid coordinate handling CodeCaster C++ 13 Jul 4th, 2005 8:07 AM
Need assistance with program DJ_Mittens C++ 4 Apr 20th, 2005 8:48 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:41 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC