sketch_square

pyhelpers.geom.sketch_square(ctr_x, ctr_y, side_length, rotation_theta=0, annotation=False, annot_font_size=12, fig_size=(6.4, 4.8), ret_vertices=False, **kwargs)

Sketch a square given its centre point, four vertices and rotation angle (in degree).

Parameters
  • ctr_x (int or float) – x coordinate of a square centre

  • ctr_y (int or float) – y coordinate of a square centre

  • side_length (int or float) – side length of a square

  • rotation_theta (int or float) – rotate (anticlockwise) the square by rotation_theta (in degree), defaults to 0

  • annotation (bool) – whether to annotate vertices of the square, defaults to True

  • annot_font_size (int) – font size annotation texts, defaults to 12

  • fig_size (tuple or list) – figure size, defaults to (6.4, 4.8)

  • ret_vertices (bool) – whether to return the vertices of the square, defaults to False

  • kwargs – [optional] parameters of matplotlib.axes.Axes.annotate

Returns

vertices of the square as an array([ll, ul, ur, lr])

Return type

numpy.ndarray

Examples:

>>> from pyhelpers.geom import sketch_square
>>> from pyhelpers.settings import mpl_preferences
>>> import matplotlib.pyplot as plt

>>> mpl_preferences()

>>> c1, c2 = 1, 1
>>> side_len = 2

>>> sketch_square(c1, c2, side_len, rotation_theta=0, annotation=True, fig_size=(5, 5))
>>> plt.show()

The above exmaple is illustrated in Fig. 12:

../_images/geom-sketch_square-demo-1.svg

Fig. 12 An example of a sketch of a square, created by the function sketch_square().

>>> sketch_square(c1, c2, side_len, rotation_theta=75, annotation=True, fig_size=(5, 5))
>>> plt.show()

This second example is illustrated in Fig. 13:

../_images/geom-sketch_square-demo-2.svg

Fig. 13 An example of a sketch of a square rotated 75 degrees anticlockwise about the centre.