irsim.lib.algorithm.generation#
This file is the implementation of the generation of random polygons.
Author: Ruihua Han
Functions#
|
Clip a value to a specified range. |
reference: https://stackoverflow.com/questions/8997099/algorithm-to-generate-random-2d-polygon |
|
|
Generate a random polygon around a center point. |
|
Generate random angle steps for polygon vertices. |
Module Contents#
- irsim.lib.algorithm.generation.clip(value: float, lower: float, upper: float) float[source]#
Clip a value to a specified range.
- Parameters:
value (float) – Value to be clipped.
lower (float) – Lower bound of the range.
upper (float) – Upper bound of the range.
- Returns:
Clipped value.
- Return type:
float
- irsim.lib.algorithm.generation.random_generate_polygon(number: int = 1, center_range: list[float] | None = None, avg_radius_range: list[float] | None = None, irregularity_range: list[float] | None = None, spikeyness_range: list[float] | None = None, num_vertices_range: list[int] | None = None, **kwargs: Any) numpy.ndarray | list[numpy.ndarray][source]#
reference: https://stackoverflow.com/questions/8997099/algorithm-to-generate-random-2d-polygon
Generate random polygons with specified properties.
- Parameters:
number (int) – Number of polygons to generate (default 1).
center_range (List[float]) – Range for the polygon center [min_x, min_y, max_x, max_y].
avg_radius_range (List[float]) – Range for the average radius of the polygons.
irregularity_range (List[float]) – Range for the irregularity of the polygons.
spikeyness_range (List[float]) – Range for the spikeyness of the polygons.
num_vertices_range (List[int]) – Range for the number of vertices of the polygons.
- Returns:
List of vertices for each polygon or a single polygon’s vertices if number=1.
- irsim.lib.algorithm.generation.generate_polygon(center: list[float], avg_radius: float, irregularity: float, spikeyness: float, num_vertices: int) numpy.ndarray[source]#
Generate a random polygon around a center point.
- Parameters:
center (Tuple[float, float]) – Center of the polygon.
avg_radius (float) – Average radius from the center to vertices.
irregularity (float) – Variance of angle spacing between vertices. Range [0, 1]
spikeyness (float) – Variance of radius from the center. Range [0, 1]
num_vertices (int) – Number of vertices for the polygon.
- Returns:
Vertices of the polygon in CCW order.
- Return type:
numpy.ndarray
- irsim.lib.algorithm.generation.random_angle_steps(steps: int, irregularity: float) list[float][source]#
Generate random angle steps for polygon vertices.
- Parameters:
steps (int) – Number of angles to generate.
irregularity (float) – Variance of angle spacing.
- Returns:
Random angles in radians.
- Return type:
List[float]