get_square_vertices

pyhelpers.geom.get_square_vertices(ctr_x, ctr_y, side_length, rotation_theta=0)[source]

Get the four vertices of a square given its centre and side length.

See also [GEOM-GSV-1].

Parameters:
  • ctr_x (int | float) – X-coordinate of the square’s centre.

  • ctr_y (int | float) – Y-coordinate of the square’s centre.

  • side_length (int | float) – Side length of the square.

  • rotation_theta (int | float) – Rotation angle (in degrees) to rotate the square anticlockwise; defaults to 0.

Returns:

Vertices of the square as an array([Lower left, Upper left, Upper right, Lower right]).

Return type:

numpy.ndarray

Examples:

>>> from pyhelpers.geom import get_square_vertices
>>> ctr_1, ctr_2 = -5.9375, 56.8125
>>> side_len = 0.125
>>> vts = get_square_vertices(ctr_1, ctr_2, side_len, rotation_theta=0)
>>> vts
array([[-6.   , 56.75 ],
       [-6.   , 56.875],
       [-5.875, 56.875],
       [-5.875, 56.75 ]])
>>> # Rotate the square by 30° (anticlockwise)
>>> vts = get_square_vertices(ctr_1, ctr_2, side_len, rotation_theta=30)
>>> vts
array([[-5.96037659, 56.72712341],
       [-6.02287659, 56.83537659],
       [-5.91462341, 56.89787659],
       [-5.85212341, 56.78962341]])