The Nightstar Zoo

Nightstar IRC Network - irc.nightstar.net
It is currently Sat Dec 16, 2017 12:17 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Strangely-shaped arrays
PostPosted: Thu Jun 17, 2004 3:29 pm 
Offline
Energizer Bunny
User avatar

Joined: Wed May 22, 2002 12:24 am
Posts: 1634
So for a recent class project I needed to make an array that acted like a triangle - specifically in such a sense where I had a size s and I had to be able to index array[j] in such a way that [i]i > 0, j > 0, and i + j < s. Eventually Pi (was it Pi? It may have been raif.) gave me some advice onthat, and I ended up with a decent thing going there - basically a 1-d array with a 2-d get/set pair. It also got me to thinking:

What strange, escherian shapes have you had for arrays?

Vorn


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 17, 2004 4:01 pm 
Offline
Nightstar Graveyard Daemon
User avatar

Joined: Mon Jun 03, 2002 8:30 pm
Posts: 1071
Location: Wouldn't you rather observe my Velocity?
Hexagons.

I needed to be able to traverse a hexagonal array. I realized that there was a direct mapping from an orthogonal grid to a hexagonal one if you allowed diagonal traversals along one diagonal but not the other. So I stored the data as a 2D array, but wrote a class that let me jump diagonally across the array as well as vertically and horizontally.

So this:

Image

Came out like this:

Code:
 1   2   3   4   5   6
 |  /|  /|  /|  /|  /|
 | / | / | / | / | / |
 |/  |/  |/  |/  |/  |
 7   8   9  10  11  12
 |  /|  /|  /|  /|  /|
 | / | / | / | / | / |
 |/  |/  |/  |/  |/  |
13  14  15  16  17  18
 |  /|  /|  /|  /|  /|
 | / | / | / | / | / |
 |/  |/  |/  |/  |/  |
19  20  21  22  23  24


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group