     var p1y = i + gsy(j, i);
                var p2x = j + gsx(j, i + grid_size);
                var p2y = i + grid_size + gsy(j, i + grid_size);
                var d1x = dx(p1x, p1y) * grid_size;
                var d1y = dy(p1x, p1y) * grid_size;
                var d2x = dx(p2x, p2y) * grid_size;
                var d2y = dy(p2x, p2y) * grid_size;
                var Ax = [
                    [1, 0, 0, 0],
                    [0, 1, 0, 0],
                    [1, 1, 1, 1],
                    [0, 1, 