I’ve been working on implementing a pure pursuit algorithm using the method described in this whitepaper. I decided to create my own path generator using JavaScript, and I’m having a strange problem with the path smoothing function.

The function I wrote is identical to the one described in the whitepaper, and I didn’t suspect a problem with it until I looked at this version of the same path generator written by @AriMB in Python. If you generate a path using my program, the longer you make the path, the more the smoothing function diverges from the original path.

The straight lines are the desired path, the red trail is the smoothed path. You can see that it handles a simple 90 degree turn just fine, but if I add another point to the path and smooth it again, the smoothed path diverges from the desired path drastically.

However, if you plot a similar path on the program by AriMB, you get a more uniform result.

I’ve compared my smoothing function to his extensively, as far as I can tell they

*should*take in the exact same inputs, and provide the exact same outputs. The only differences I see pertain to the different syntax of Python. This is my smoothing function:

```
var smoothPath = function(Path, A, B, tolerance) {
var tempPath = Path;
var change = tolerance;
while (change >= tolerance) {
change = 0.0;
for (var i = 1; i < Path.length-1; i++) {
for (var j = 0; j < Path[i].length-1; j++) {
var aux = tempPath[i][j];
tempPath[i][j] += A * (Path[i][j] - tempPath[i][j]) + B * (tempPath[i-1][j] + tempPath[i+1][j] - (2.0 * tempPath[i][j]));
change += Math.abs(aux - tempPath[i][j]);
}
}
}
return tempPath;
};
```

And this is AriMB’s smoothing function:

```
while change >= tolerance:
change = 0
for i in range(0, len(total_waypoints)-1):
for j in range(len(total_waypoints[i])):
aux = smooth_waypoints[i][j]
number+=1
smooth_waypoints[i][j] += weight_data*(total_waypoints[i][j]-smooth_waypoints[i][j]) + \
weight_smooth*(smooth_waypoints[i-1][j]+smooth_waypoints[i+1 [j]-2*smooth_waypoints[i][j])
change += abs(aux - smooth_waypoints[i][j])
changes.append((total_waypoints[i][j]))
```

There are several input parameters to the smoothing algorithm that I made sure to set to the same values used in the python implementation (called A, B, and tolerance in my function). Yet my function still produces a much different output.

I’ve done a lot of debugging, and I’m fresh out of ideas. Is there something I’m missing here? Do the JavaScript math functions I’m using behave somehow differently than those used in Python?

Edit: I should probably mention, that when running my function with the same inputs as AriMD’s, it generates basically a straight line due to the tolerance value being so low. But again, I still don’t understand why the function behaves so differently.