I want to achieve the following:
- 1) get coordinates of the rotated patch
- 2) get all points of the patch (here: rectangle)
- ** I have an impression that the rotated rectangle does not have 90 degree between faces. Is that just visualization?
My snippet below. The coordinates of the rotated patch are the same as of the original though .. How to achieve 1) and 2) ?
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import matplotlib as mpl
from matplotlib.transforms import Affine2D
fig = plt.figure()
ax = fig.add_subplot(111)
angle = np.deg2rad(45)
r1 = patches.Rectangle((8,4), 5,3, fill=False, color="red", alpha=0.50)
r2 = patches.Rectangle((8,4), 5,3, fill=False, color="blue", alpha=0.50)
trafo = mpl.transforms.Affine2D().rotate_around(8,4,angle) + ax.transData
r2.set_transform(trafo)
ax.add_patch(r1)
ax.add_patch(r2)
plt.xlim(0,15)
plt.ylim(0,15)
plt.grid(False)
plt.show()
print(r1.get_bbox())
print(r1.get_xy())
print(r2.get_bbox()) # why are they the same as for r1?
print(r2.get_xy())
#print(r1.get_all_points()) # how to achieve it?
Rectangle's coordinates
A
Rectangle
is defined through a coordinate pair of the lower left corner (x,y), and a width and height. To get the coordinates of its corners, you maycalculate them from the corner, width and height,
get them from the transformed path,
In both cases the printed result will be
You may also get the two points of the lower left and upper right corner from the rectangle's bounding box (due to a box being a Rectangle itself),
with will result in
Transformed rectangle's coordinates.
Now if you transform the rectangle, the above methods need to take the transform into account to provide the correct coordinates of the transformed rectangle.
transform the manually obtained coordinates,
transform the coordinates obtained from the path
In those cases, the printed coordinates will be
Or, in case of getting the coodinates from the bounding box
prints