Skip to content
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

Tweak polar distance #6226

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

teunbrand
Copy link
Collaborator

@teunbrand teunbrand commented Dec 10, 2024

This PR aims to fix #5023.

Briefly, it exaggerates the radius value so that more segments are munched near small-r coordinates.

I've given the issue some thought and while I believe that the current calculation of the distance is correct, it does not quite match our intuition.

When we break up a curve into segments, we can get away with using less segments for parts with less curvature without it being noticible because the angle between subsequent segments isn't very large. Given the formula for curvature $\kappa = \frac{1}{R}$, it stands to reason that smaller circles with smaller $R$ have more curvature. Greater curvature makes the angles between segments larger with the same segment length, compared to larger circels (i.e. less curvature).

To compensate for this, in this PR I decided that 'correctness' of the distance calculation is subservient to looking good. To preserve distances at $R = 0$ and $R = 1$, I've chosen $x^{0.75}$ as the method by which to boost smaller $R$. It gives both small $R$ and big $R$ a boost, but proportionally this boosts small $R$ more. The formula is a subjective choice: I felt like sqrt(x) was slightly too agressive. We could go with something like function(x, n = 3) x + n * (x^(1 / n) - x)^n to boost smaller $R$ without boosting big $R$ too much, but I like the simplicity of the current boosting.

This is a detail of the reprex in the linked issue with the current main branch:

image

This is a detail of the same area with this PR. You still see the angles, but it isn't as egregious.

image

Overall the entire grob went from having 61 points previously to 88 points now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Polygon segments with coord_polar() near 0
1 participant