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

Cubic bezier curves and straight (horizontal or vertical) bezier curves intersection #76

Open
harjis opened this issue Jun 5, 2017 · 5 comments
Labels

Comments

@harjis
Copy link

harjis commented Jun 5, 2017

Hi!

First of all great work with the library! Has saved me a ton of time.

The issue I have is an intersection with cubic bezier curves and straight horizontal or vertical bezier curve. My code is as follows:

    const r = 150;
    const k = 0.55228;
    const circleArc = [
      { x: r * 2, y: r }, // Intersection point
      { x: r * 2, y: r + k * r },
      { x: r + k * r, y: r * 2 },
      { x: r, y: r * 2 }
    ];
    const straightLine = [
      { x: r, y: r },
      { x: r * 2, y: r }, //Intersection point
      { x: r * 2 + k * r, y: r },
      { x: r * 4, y: r }
    ];
    const circleArcBezier = new Bezier([...circleArc]);
    const straighLineBezier = new Bezier([...straightLine]);

    console.log(circleArcBezier.intersects(straighLineBezier)); // Empty array

To my understanding the lines should intersect each other at point { x: r * 2, y: r }. Also If I change the straight line even 1px the intersection is detected.

screen shot 2017-06-05 at 10 36 57

Happens in Chrome Version 58.0.3029.110 (64-bit) and Firefox 53.0.3 (64-bit) at least with version 2.2.3

@Pomax Pomax added the bug label Jun 5, 2017
@Pomax
Copy link
Owner

Pomax commented Jun 5, 2017

Using a bezier curve to represent a straight line's a little odd, but that should still work. It might be IEEE floating points causing a problem here, but I'll have to log what t values and segment coordinates the algorithm comes up with the know for sure.

@rogercampos
Copy link

Having the same issue. Still, awesome lib! 👍

@Pomax
Copy link
Owner

Pomax commented Nov 4, 2020

I'll have a look to see if I can improve that, but the main reason for this is that it's trying to resolve the intersection as a curve/curve intersection rather than going "this is a degenerate curve, I should just check for line intersection".

@rogercampos
Copy link

I understand it doesn't make sense to use bezier curves when you really have straight lines, but i'm creating a tool where the user can control the shape of the grid (built with cubic bezier lines), so it's possible this happens, sometimes:

Screenshot 2020-11-04 at 16 51 23

@Pomax
Copy link
Owner

Pomax commented Nov 4, 2020

I didn't say it doesn't make sense, I said the code needs to know that it's dealing with a degerenate curve, and that it should automatically fall down to line/curve intersection instead of trying to do the iterative curve/curve intersection detection, which is far more sensitive to IEEE floating point rounding errors.

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

No branches or pull requests

3 participants