Jump to content

moving into a parallelepiped

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
MrBlue

MrBlue

    Newbie

  • Members
  • Pip
  • 5 posts
Hello there !
I am new to the forum, I looked back in the previous posts, but I cannot find a solution or an help for following issue.
Let’s consider a parallelepiped composed by a number of cubic elements, similar to a Rubik cube.
Every element is identified by a three dimensional array (direction i,j,k, respectively.). In shorts it is a three dimensional matrix.
I’d like to create an algorithm in order to move into this series of cubes, as a “snake” would do.
That is: I want to move completely in a line – therefore moving from one side to the other of the parallelepiped – and then change line.
When I move in the first line there are no problems, since to indexes remain constant (let’s say, j, k) and the third one (i) changes.
I can manage it with a simple for cycle, changing i from 0 to number of elements in i direction.
When this line ends, I can move following three possibilities :
1) on the line over
2) on the line beneath
3) on a line different from 1) and 2)
In these cases, one of the two index (j or k) change, but in both cases, I shall decrease instead than increase.
My first problem is how to tell to the code than when I change the line the i index shall be decreased, on the second pass, while on the third pass it has to be increased and so on.
(ex, I am in the element (1,1,1) and the parallelepiped has got i = 10, j = 3, k = 3, I move changing the i elements until they reach 10, getting into element (10,1,1).The next step is going to element (10,1,2), but then I have to decrease i, going to (9,1,2). Once got to (1,1,2) I want to go to (2,1,2) and so on). In this case I am considering case 1)
Once solved this issue, I’d like to generate an algorithm in order to improve automatically the k value once ended the first line (I will chose to move on the line over) and to change the j value once after k passing back an forth
(ex, the parallelepiped has got i = 10, j = 3, k = 3; once got to (10,1,3) I’d like to move to (10,2,3) and then (9,2,3)
I’m getting stuck in this issues.
Please, can somebody help me ?
Many thanks

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Based on your description, I have no clear idea of what you're trying to accomplish. Are you trying to hit all the nodes in the grid with the minimum number of moves? Are you trying to reach a particular point? Something else?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
MrBlue

MrBlue

    Newbie

  • Members
  • Pip
  • 5 posts
Hi, many thanks for your answer.
Indeed I am trying to hit all the nodes in the grid.
let's consider my example:if I would start from node (1,1,1) , I'd like to reach to node (10,3,3), but moving in the way described in the previous post (first all i nodes, then k increased by one and again moving on i axis, ...)

Many thanks

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Are you trying to minimize the number of moves, or just go in a specific pattern?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
MrBlue

MrBlue

    Newbie

  • Members
  • Pip
  • 5 posts
Hi thanks for your answer and sorry for not being clear.
Just go in a specific pattern.

Thanks in advance

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You probably just need a few loops, and a couple variables to determine which direction you're going in.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog