Pomax / bezierjs

A nodejs and client-side library for (cubic) Bezier curve work
MIT License
1.7k stars 230 forks source link

`intersects(line)` returns `[]` When one of Bessel's endpoints is on a horizontal line segment #179

Open nxjniexiao opened 2 years ago

nxjniexiao commented 2 years ago

Hi!

intersects(line) returns [] When one of Bessel's endpoints is on a horizontal line segment.

It is similar to #76 .

const { Bezier } = require("bezier-js");

const fromPos = [629, 340.5];
const fromPosCP = [791.875, 537.03515625];
const toPosCP = [741.75, 366.5];
const toPos = [920.75, 415.5];

const b = new Bezier([...fromPos, ...fromPosCP, ...toPosCP, ...toPos]);

const line = {
  p1: { x: 900, y: 415.5 },
  p2: { x: 950, y: 415.5 }
};

console.log(b.intersects(line)); // []

Obviously toPos is on the line, but intersects(line) returns [].

ShaMan123 commented 5 months ago

I can reproduce When I tilt the line a bit it works but an epsilon tilt is not enough

ShaMan123 commented 5 months ago

Ray cast using (0, 1) vector from the center of the beetle

Screenshot 2024-01-17 at 8 27 19

Ray cast using (1, 50) vector from the center of the beetle

Screenshot 2024-01-17 at 8 29 01
ShaMan123 commented 5 months ago

Could it be related to the fact that it this case the intersection occurs at the min/max point of a curve?

ShaMan123 commented 5 months ago

I think I got it wrong Will update next week with findings