This function creates a square mesh by sampling nodes uniformly on a square and then connecting these nodes with edges. The nodes are distributed based on the provided side length and number of segments. Horizontal, vertical, and diagonal edges are generated to fully connect the mesh. The function returns a list containing the nodes and edges, along with data frames and a ggplot object for visualization.
generate_mesh_data(.side_length = 1, .n_seg = 1)
A list containing:
A matrix with coordinates of the nodes.
A list of edges connecting the nodes.
A data frame of nodes for ggplot.
A data frame of edges for ggplot.
A ggplot object visualizing the nodes and edges.
Additionally, the list contains attributes:
The side length used to generate the mesh.
The number of segments used to generate the mesh.
Dimensions of the nodes data frame.
Dimensions of the edges data frame.
A single numeric value representing the side length of the square.
A positive integer representing the number of segments along each side of the square.
Steven P. Sanderson II, MPH
This function generates a mesh of nodes and edges based on the provided side length and number of segments.
This function creates a square mesh of nodes and edges, where the nodes are sampled uniformly on a square. The edges are generated to connect the nodes horizontally, vertically, and diagonally.
generate_mesh_data(1, 1)
generate_mesh_data(1, 2)
Run the code above in your browser using DataLab