-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Path.arc is broken for clockwise arcs #13717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It is by pure convention that angles are usually measured counter-clockwise, but there are some good reasons for that; https://en.wikipedia.org/wiki/Right-hand_rule#Coordinates, https://en.wikipedia.org/wiki/Orientation_(vector_space), https://en.wikipedia.org/wiki/Complex_number#Exponentiation Of course this is again based on the convention of the x axis being the horizontal axis and denoting ordinates and in the end one could of course define everything just the other way around. But I suppose it makes sense for matplotlib to follow those conventions and hence define the direction of the arc in counter-clockwise direction. I do agree that this is not very obvious from the documentation. While I will hence label this with "documentation". Though, if you think that this issue is not solved by clearly stating in the docs that arcs are defined counter-clockwise, please feel free to clarify. |
Hej, first of all I want to point out my gratitude for the entire matplotlib-team's valuable and good work, that slipped my attention in the initial posting :) Now concerning the issue: I am aware of the convention, but from the documentation it wasn't clear that it would be enforced instead of sticking to the input logic, so I think adjusting the documentation would be very helpful. Further, if one does not think with a certain direction in mind, I think that the expression "produce the shortest arc within 360 degrees" could actually suggest that the arc is never longer than 180 degrees (Yay to the pain that is angle wrapping). Now as for the functionality: The following is very subjective and quite possibly influenced by my very limited knowledge of the path module and bezier curves. If you prefer to leave the functionality as it currently is, maybe the following snippet could be added to documentation, I have finally figured out how to traverse the arc in the direction I want without changing the code of path.arc itself. if t0 <= t1:
arc = Path.arc(t0, t1)
if t0 > t1:
arc = Path.arc(t1, t0)
codes = list(arc.codes[:])
verts = list(arc.vertices[:])
verts = verts[::-1]
codes = codes[::-1]
codes[0], codes[-1] = codes[-1], codes[0]
arc = Path(verts, codes) EDIT: Improved snippet readability |
Thanks for the detailing this; to summarize, there are two action items here:
|
Nice :) If I find some time in the upcoming week I will try to test how bulletproof the current and modified angle wrapping logic are and potentially make a pull request :) |
I wonder if it would make more sense to have a generic Path().reverse() method, rather than having to add this functionality to each path generator separately (in fact, it's basically already there (privately) as |
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
Bug report
Bug summary
When calling Path.arc in a clockwise fashion (theta1 > theta2) , the angle wrapping results in drawing the arc over the opposing angle in a counterclockwise direction.
Code for reproduction
Actual outcome
Expected outcome
The direction of the arc should not matter, either direction should draw an arc that covers 2 degrees, and the vertices generated by the function should go in the direction chosen by the user.
Proposed fix
For my purposes I fixed the problem by adding another condition into the angle wrapping logic.
This assures that directionality is kept and the correct angle is covered.
Matplotlib version
Probably irrelevant but:
The text was updated successfully, but these errors were encountered: