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)[source]¶
Sketch a square on a plot given its centre coordinates, side length and rotation angle.
This function plots a square with its centre at coordinates
(ctr_x, ctr_y)
, side lengthside_length
, and rotated by rotation_theta degrees (anticlockwise).- Parameters:
ctr_x (int | float) – X coordinate of the centre of the square.
ctr_y (int | float) – Y coordinate of the centre of the square.
side_length (int | float) – Side length of the square.
rotation_theta (int | float) – Rotation angle of the square in degrees; defaults to
0
.annotation (bool) – Whether to annotate vertices of the square; defaults to
True
.annot_font_size (int) – Font size of annotation texts; defaults to
12
.fig_size (tuple | list) – Size of the figure; defaults to
(6.4, 4.8)
.ret_vertices (bool) – Whether to return the vertices of the square; defaults to
False
.kwargs – Additional parameters for
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(backend='TkAgg') >>> c1, c2 = 1, 1 >>> side_len = 2 >>> sketch_square(c1, c2, side_len, rotation_theta=0, annotation=True, fig_size=(5, 5)) >>> plt.show() >>> # from pyhelpers.store import save_fig >>> # path_to_fig_ = "docs/source/_images/geom-sketch_square-demo-1" >>> # save_fig(f"{path_to_fig_}.svg", verbose=True) >>> # save_fig(f"{path_to_fig_}.pdf", verbose=True)
The above exmaple is illustrated in Figure 17:
>>> sketch_square(c1, c2, side_len, rotation_theta=75, annotation=True, fig_size=(5, 5)) >>> plt.show() >>> # save_fig("docs/source/_images/geom-sketch_square-demo-2.svg", verbose=True) >>> # save_fig("docs/source/_images/geom-sketch_square-demo-2.pdf", verbose=True)
This second example is illustrated in Figure 18: