Main problem
Let the data be defined as:
step = 3; %// step size x0 = 8; %// x coordinate of origin y0 = 12; %// y coordinate of origin N = 32; %// number of steps
Then the coordinates of the spiral can be obtained as values ββin the complex plane as follows: β :
z = x0+1j*y0 + step*cumsum([0 -1j.^(-floor(sqrt(4*(0:N)+1))-1)]);
Of course, the x and y coordinates then
x = real(z); y = imag(z);
With the above examples, plot(z,'o-') values ββ(or plot(x,y,'o-') ) produces a graph

β The key was to generate the sequence 1,2,3,3,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,8... I must OEIS for solving this part . The sequence turns out to be the integer part of the square root of 4n + 1, for n = 1,2,3, ...
How to enable overlap and window size
To account for a match, following Daniel's suggestion , subtract its value from step .
To consider the size of the window, N must be large enough for the spiral to reach a point from the border of the window; and then only the previous points will be saved.
Since it is difficult to calculate in advance how large N , one possible approach is to exponentially increase N in the cycle until it becomes large enough. An exponential increase ensures that the number of iterations of the loop is small. The code below uses the values ββ2 for N
%// Data step = 3; %// step size overlap = 1; %// overlap x0 = 20; %// x coordinate of origin y0 = 15; %// y coordinate of origin xmin = 0; %// window boundary: min x xmax = 40; %// window boundary: max x ymax = 30; %// window boundary: min y ymin = 0; %// window boundary: max y %// Computations stepov = step-overlap; N = 8; %// Initial value. Will be increased as needed done = false; while ~done z = x0+1j*y0 + stepov*cumsum([0 -1j.^(-floor(sqrt(4*(0:N)+1))-1)]); %// compute coordinates of N points ind = find(real(z)<xmin | real(z)>xmax | imag(z)<ymin | imag(z)>ymax, 1); %// find index of first z out of boundary, if any done = ~isempty(ind); %// exit if we have reached outside window boundary N = N*2; %// increase number of steps for next try end z = z(1:ind-1); %// only keep values that are within the boundary x = real(z); y = imag(z);
With the data specified in the code, the resulting schedule is as follows. Note that the last point is (38.0). The next item will be (38, -2), which is outside the window border.
