Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Grid with a different number of points per side #745

Open
hellcastter opened this issue May 4, 2024 · 0 comments
Open

Grid with a different number of points per side #745

hellcastter opened this issue May 4, 2024 · 0 comments

Comments

@hellcastter
Copy link

It seems like current implementation has no opportunity to create an evenly spaced grid, or just a grid with a different number of points per side. I came up with this solution.

def build_point_grid(n_per_x_side: int, n_per_y_side: int, n_layers: int, scale_per_layer: int) -> np.ndarray:
    """Generates a 2D grid of points evenly spaced"""
    x_min, x_max = 0, 1
    y_min, y_max = 0, 1

    points_list = []

    for _ in range(n_layers + 1):
      x_offset = (x_max - x_min) / (2 * n_per_x_side)
      y_offset = (y_max - y_min) / (2 * n_per_y_side)

      points_x = np.linspace(x_min + x_offset, x_max - x_offset, n_per_x_side)
      points_y = np.linspace(y_min + y_offset, y_max - y_offset, n_per_y_side)

      points_grid = np.stack(np.meshgrid(points_x, points_y), axis=-1)
      points = points_grid.reshape(-1, 2)

      points_list.append(points)

      n_per_x_side //= scale_per_layer
      n_per_y_side //= scale_per_layer

    return points_list

I think it's good to add this to implementation and change points_per_side to points_per_side (int or tuple[2] or None)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant