irsim.lib.algorithm.generation#

This file is the implementation of the generation of random polygons.

Author: Ruihua Han

Functions#

clip(→ float)

Clip a value to a specified range.

random_generate_polygon(...)

reference: https://stackoverflow.com/questions/8997099/algorithm-to-generate-random-2d-polygon

generate_polygon(→ numpy.ndarray)

Generate a random polygon around a center point.

random_angle_steps(→ list[float])

Generate random angle steps for polygon vertices.

Module Contents#

irsim.lib.algorithm.generation.clip(value: float, lower: float, upper: float) float[源代码]#

Clip a value to a specified range.

参数:
  • value (float) -- Value to be clipped.

  • lower (float) -- Lower bound of the range.

  • upper (float) -- Upper bound of the range.

返回:

Clipped value.

返回类型:

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][源代码]#

reference: https://stackoverflow.com/questions/8997099/algorithm-to-generate-random-2d-polygon

Generate random polygons with specified properties.

参数:
  • 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.

返回:

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[源代码]#

Generate a random polygon around a center point.

参数:
  • 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.

返回:

Vertices of the polygon in CCW order.

返回类型:

numpy.ndarray

irsim.lib.algorithm.generation.random_angle_steps(steps: int, irregularity: float) list[float][源代码]#

Generate random angle steps for polygon vertices.

参数:
  • steps (int) -- Number of angles to generate.

  • irregularity (float) -- Variance of angle spacing.

返回:

Random angles in radians.

返回类型:

List[float]