2D Geometry Utils#

Gymnasium-Planar-Robotics offers various functions that are mainly used for collision checking in the 2D (x,y)-plane. However, they may also help to develop your custom planar robotics environments.

gymnasium_planar_robotics.utils.geometry_2D_utils.check_line_segments_intersect(p1: ndarray, p2: ndarray, q1: ndarray, q2: ndarray) bool[source]

Check whether two line segments p and q intersect by considering the orientation of ordered points, as explained here: https://www.dcs.gla.ac.uk/~pat/52233/slides/Geometry1x1.pdf. The two line segments are each defined by two points in the (x,y)-plane (p1 and p2; q1 and q2). This function is vectorized and can perform multiple checks. In the case of multiple tests, the line segments given by the points p1[i,:], p2[i,:], q1[i,:], q2[i,:] are tested.

Parameters:
  • p1 – a numpy array of shape (num_checks,2) specifying the first points belonging to p

  • p2 – a numpy array of shape (num_checks,2) specifying the second points belonging to p

  • q1 – a numpy array of shape (num_checks,2) specifying the first points belonging to q

  • q2 – a numpy array of shape (num_checks,2) specifying the second points belonging to q

Returns:

a numpy array of shape (num_checks,), where an entry is True if the two line segments intersect, False otherwise

gymnasium_planar_robotics.utils.geometry_2D_utils.get_2D_rect_vertices(qpos: ndarray, size: ndarray) ndarray[source]

Get the (x,y) coordinates of the vertices of rectangles w.r.t. the base frame. This function is vectorized and can calculate the vertices of multiple rectangles.

Parameters:
  • qpos – qpos (position and orientation) of the rectangles specified as a numpy array of shape (num_rectangles,7) (x_p,y_p,z_p,w_o,x_o,y_o,z_o)

  • size – length and width (half-size) of the rectangles specified as a numpy array of shape (num_rectangles,2)

Returns:

the (x,y) coordinates of the vertices (numpy array of shape (num_rectangles,2,4))

gymnasium_planar_robotics.utils.geometry_2D_utils.check_rectangles_intersect(qpos_r1: ndarray, qpos_r2: ndarray, size_r1: ndarray, size_r2: ndarray) bool[source]

Check whether two rectangles of any orientation intersect. This function is vectorized and can perform multiple checks, i.e. it is checked whether the rectangles with qpos qpos_r1[i,:] and qpos_r2[i,:] and sizes size_r1[i,:] and size_r2[i,:] intersect.

Parameters:
  • qpos_r1 – qpos (position and orientation) of the first rectangles specified as a numpy array of shape (num_checks,7) (x_p,y_p,z_p,w_o,x_o,y_o,z_o)

  • qpos_r2 – qpos (position and orientation) of the second rectangles specified as a numpy array of shape (num_checks,7) (x_p,y_p,z_p,w_o,x_o,y_o,z_o)

  • size_r1 – length and width (half-size) of the first rectangles specified as a numpy array of shape (num_checks,2)

  • size_r2 – length and width (half-size) of the second rectangles specified as a numpy array of shape (num_checks,2)

Returns:

a numpy array of shape (num_checks,), where an entry is True if the rectangles intersect, False otherwise