@@ -1654,33 +1654,59 @@ def get_corners(self):
1654
1654
return self .get_patch_transform ().transform (
1655
1655
[(- 1 , - 1 ), (1 , - 1 ), (1 , 1 ), (- 1 , 1 )])
1656
1656
1657
+ def _calculate_length_between_points (self , x0 , y0 , x1 , y1 ):
1658
+ return np .sqrt ((x1 - x0 )** 2 + (y1 - y0 )** 2 )
1659
+
1660
+ def _calculate_vertices_coordinates (self , return_major : bool = True ):
1661
+ # calculate the vertices of width axis
1662
+ w_x0 = self ._center [0 ] - self ._width / 2 * np .cos (np .deg2rad (self ._angle ))
1663
+ w_y0 = self ._center [1 ] - self ._width / 2 * np .sin (np .deg2rad (self ._angle ))
1664
+ w_x1 = self ._center [0 ] + self ._width / 2 * np .cos (np .deg2rad (self ._angle ))
1665
+ w_y1 = self ._center [1 ] + self ._width / 2 * np .sin (np .deg2rad (self ._angle ))
1666
+
1667
+ # calculate the vertices of height axis
1668
+ h_x0 = self ._center [0 ] - self ._height / 2 * np .sin (np .deg2rad (self ._angle ))
1669
+ h_y0 = self ._center [1 ] + self ._height / 2 * np .cos (np .deg2rad (self ._angle ))
1670
+ h_x1 = self ._center [0 ] + self ._height / 2 * np .sin (np .deg2rad (self ._angle ))
1671
+ h_y1 = self ._center [1 ] - self ._height / 2 * np .cos (np .deg2rad (self ._angle ))
1672
+
1673
+ if self ._calculate_length_between_points (
1674
+ w_x0 , w_y0 , w_x1 , w_y1
1675
+ ) >= self ._calculate_length_between_points (
1676
+ h_x0 , h_y0 , h_x1 , h_y1
1677
+ ): # width is major
1678
+ major = [(w_x0 , w_y0 ), (w_x1 , w_y1 )]
1679
+ minor = [(h_x0 , h_y0 ), (h_x1 , h_y1 )]
1680
+ else : # minor
1681
+ major = [(h_x0 , h_y0 ), (h_x1 , h_y1 )]
1682
+ minor = [(w_x0 , w_y0 ), (w_x1 , w_y1 )]
1683
+
1684
+ if return_major :
1685
+ coordinates = major
1686
+ else :
1687
+ coordinates = minor
1688
+
1689
+ return coordinates
1690
+
1657
1691
def get_vertices (self ):
1658
1692
"""
1659
- Return the left and right vertex coordinates of the ellipse.
1693
+ Return the vertices coordinates of the ellipse.
1660
1694
1661
1695
The definition can be found `here <https://en.wikipedia.org/wiki/Ellipse>`_
1662
1696
1663
1697
.. versionadded:: 3.8
1664
1698
"""
1665
- x0 = self ._center [0 ] - self ._width / 2 * np .cos (np .deg2rad (self ._angle ))
1666
- y0 = self ._center [1 ] - self ._width / 2 * np .sin (np .deg2rad (self ._angle ))
1667
- x1 = self ._center [0 ] + self ._width / 2 * np .cos (np .deg2rad (self ._angle ))
1668
- y1 = self ._center [1 ] + self ._width / 2 * np .sin (np .deg2rad (self ._angle ))
1669
- return [(x0 , y0 ), (x1 , y1 )]
1699
+ return self ._calculate_vertices_coordinates ()
1670
1700
1671
1701
def get_co_vertices (self ):
1672
1702
"""
1673
- Return the left and right co-vertex coordinates of the ellipse.
1703
+ Return the co-vertices coordinates of the ellipse.
1674
1704
1675
1705
The definition can be found `here <https://en.wikipedia.org/wiki/Ellipse>`_
1676
1706
1677
1707
.. versionadded:: 3.8
1678
1708
"""
1679
- x0 = self ._center [0 ] - self ._height / 2 * np .sin (np .deg2rad (self ._angle ))
1680
- y0 = self ._center [1 ] + self ._height / 2 * np .cos (np .deg2rad (self ._angle ))
1681
- x1 = self ._center [0 ] + self ._height / 2 * np .sin (np .deg2rad (self ._angle ))
1682
- y1 = self ._center [1 ] - self ._height / 2 * np .cos (np .deg2rad (self ._angle ))
1683
- return [(x0 , y0 ), (x1 , y1 )]
1709
+ return self ._calculate_vertices_coordinates (return_major = False )
1684
1710
1685
1711
1686
1712
class Annulus (Patch ):
0 commit comments