Equation for algorithm

laserblue

New member
Joined
Feb 20, 2015
Messages
1
I have an algorithm but I would prefer an equation if possible but I do not know where to begin.

I have a relation between 2 sets of numbers, P and H.

The P set of numbers can be visualized as a number line that starts on the bottom left of a matrix and moves up the matrix in a serpentine manner. The matrix has C columns and R rows. This is a field of numbered experimental plots. C and R are always known and are constants.

The set H, is formed by harvesting plots in the field by going up the first column, down the last column then up the second column in a kind of spiral pattern until the field is completely harvested.

I want an equation that gives H given C, R, and P.

My algorithm finds coordinates for P and converts them to H. First I compute the y coordinate:

. . .Py = Int[(P-1)/C] + 1

Then, if Py is even (Py mod 2 = 0), then:

. . .Px = Cy + 1 - P ( or C - [(P-1) mod C] - 1

If Py is odd, then:

. . .Px = P-C(y-1) or [(P-1) mod C] - 1

Then compute last column harvested in up direction as Split = Int[(C+1)/2]…

Now, if Px <= Split, H = 2R(Px-1) + Py. If Px > Split, then H = 2R(C-Px+1)-Py +1.

The graph looks like a spiky sine wave with a Secant wave within it. If C = 5, R = 4 and P = 17, then H = 13.

Could this be set up like a rotation matrix? Could I use some kind of discrete sine wave? Can I avoid having ro compute whether Px is odd or even? How can I set this up to get an equation or a system of simultaneous equations?
 
Last edited by a moderator:
Top