Return a `Path` representing a circle of a given radius and center. Parameters ---------- center : (float, float), default: (0, 0) The center of the circle. radius : float, default: 1 The radius of the circle. readonly : bool
(cls, center=(0., 0.), radius=1., readonly=False)
| 858 | |
| 859 | @classmethod |
| 860 | def circle(cls, center=(0., 0.), radius=1., readonly=False): |
| 861 | """ |
| 862 | Return a `Path` representing a circle of a given radius and center. |
| 863 | |
| 864 | Parameters |
| 865 | ---------- |
| 866 | center : (float, float), default: (0, 0) |
| 867 | The center of the circle. |
| 868 | radius : float, default: 1 |
| 869 | The radius of the circle. |
| 870 | readonly : bool |
| 871 | Whether the created path should have the "readonly" argument |
| 872 | set when creating the Path instance. |
| 873 | |
| 874 | Notes |
| 875 | ----- |
| 876 | The circle is approximated using 8 cubic Bézier curves, as described in |
| 877 | |
| 878 | Lancaster, Don. `Approximating a Circle or an Ellipse Using Four |
| 879 | Bezier Cubic Splines <https://www.tinaja.com/glib/ellipse4.pdf>`_. |
| 880 | """ |
| 881 | MAGIC = 0.2652031 |
| 882 | SQRTHALF = np.sqrt(0.5) |
| 883 | MAGIC45 = SQRTHALF * MAGIC |
| 884 | |
| 885 | vertices = np.array([[0.0, -1.0], |
| 886 | |
| 887 | [MAGIC, -1.0], |
| 888 | [SQRTHALF-MAGIC45, -SQRTHALF-MAGIC45], |
| 889 | [SQRTHALF, -SQRTHALF], |
| 890 | |
| 891 | [SQRTHALF+MAGIC45, -SQRTHALF+MAGIC45], |
| 892 | [1.0, -MAGIC], |
| 893 | [1.0, 0.0], |
| 894 | |
| 895 | [1.0, MAGIC], |
| 896 | [SQRTHALF+MAGIC45, SQRTHALF-MAGIC45], |
| 897 | [SQRTHALF, SQRTHALF], |
| 898 | |
| 899 | [SQRTHALF-MAGIC45, SQRTHALF+MAGIC45], |
| 900 | [MAGIC, 1.0], |
| 901 | [0.0, 1.0], |
| 902 | |
| 903 | [-MAGIC, 1.0], |
| 904 | [-SQRTHALF+MAGIC45, SQRTHALF+MAGIC45], |
| 905 | [-SQRTHALF, SQRTHALF], |
| 906 | |
| 907 | [-SQRTHALF-MAGIC45, SQRTHALF-MAGIC45], |
| 908 | [-1.0, MAGIC], |
| 909 | [-1.0, 0.0], |
| 910 | |
| 911 | [-1.0, -MAGIC], |
| 912 | [-SQRTHALF-MAGIC45, -SQRTHALF+MAGIC45], |
| 913 | [-SQRTHALF, -SQRTHALF], |
| 914 | |
| 915 | [-SQRTHALF+MAGIC45, -SQRTHALF-MAGIC45], |
| 916 | [-MAGIC, -1.0], |
| 917 | [0.0, -1.0], |
no test coverage detected