A very interesting problem! Thanks for posting. I've done a few experiments of my own on graph paper. Here are some numbers (TS = Track Spacing, A = area in square units, and L = # legs):

The pattern here is clear: adding two length units to the sides of the square increases the number of legs by 4, assuming the track spacing is constant.

Now, what happens when you keep the area constant but vary the track spacing? Here's some more data:

The pattern here is a bit less clear. The sequence doesn't show up in the Online Encyclopedia of Integer Sequences. One thing I notice is that if you add three to all the Leg numbers, you get an interesting sequence:

That kinda makes sense, because in all my drawings, if I started going north, I ended up going north on the last leg. That means all the numbers in the Leg column, except for 0, are always going to be congruent to 1 modulo 4 (That is, you always go north, east, south, west, north, east, south, west, ... , north, east, south, west, north.)

Breakthrough:focus on the number of times you go north. It's going to be

So this formula is telling you that if you take the square root of the area, you get the length of one side, right? (You have squares). Take half of that, and you get half of the length of one side. That's the amount of space your "norths" have to cover. And if you divide again by the track spacing, and round up (that's what the funny little symbols mean), you get the number of times you go north. The rest of the formula goes like this:

So that's your formula. It does not appear to work for the limiting case of It should give zero, whereas the actual value coming out of the expression is 1. However, this is not, presumably, a worrisome thing, because this limiting case consists of someone just parking out in the middle of the square and looking! Most of the time, I would assume, the area to cover is too big to do that.

Hope this helps.