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

Improvements to the offsetting code #381

Open
jonschz opened this issue Mar 28, 2023 · 0 comments
Open

Improvements to the offsetting code #381

jonschz opened this issue Mar 28, 2023 · 0 comments

Comments

@jonschz
Copy link

jonschz commented Mar 28, 2023

Dear Pomax,

first of all, thank you so much for your work! My project would not have been possible without it. I gave the due credits in multiple places.

My project involved implementing a variant of your offsetting algorithm in LaTeX (you can check it out at https://github.com/jonschz/tikz-nfold if you are interested). While implementing the code I discovered some improvements which I explain here, p. 6 ff in detail. A quick summary:

  • return abs$1(acos$1(s)) < pi$1 / 3;
    This check is equivalent to s > 1/2; furthermore, the abs() is redundant because acos() never returns a negative value.
  • // TODO: add special handling for degenerate (=linear) curves.
    It is possible to get around computing the origin altogether, as I explained here, pp. 7–8. Essentially, using a bit of geometry and trigonometry one can find a closed formula for the intersection points that does not have a singularity when the origin approaches infinity (i.e. when the control points approach a straight line). The clockwise/anticlockwise checks are also no longer needed, and most (or all) trigonometric function calls can be removed.
  • __normal2(t) {
    const d = this.derivative(t);
    const q = sqrt$1(d.x * d.x + d.y * d.y);
    return { x: -d.y / q, y: d.x / q };
    }
    As far as I can tell, computing the normal in t=0 and t=1 will not work if the first two or the last two control points are equal. I computed the tangent (and hence the normal) in t=0 as follows (pseudocode):
    if (points[0] != points[1]) { tangent = normalize(points[1]-points[0]); }
    else if (points[0] != points[2]) { tangent = normalize(points[2]-points[0]); }
    else if (points[0] != points[3]) { tangent = normalize(points[3]-points[0]); }
    else { error("Curve is degenerate to a point"); tangent = (1,0[,0]); }

Don't feel obligated to implement any of these improvements, I merely wanted to share what I found out.

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

No branches or pull requests

1 participant