2021-10-17 17:34:55 +02:00
|
|
|
***
|
|
|
|
|
|
|
|
## title: lineIntersectsCurve()
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
```js
|
|
|
|
array | false utils.lineIntersectsCurve(
|
|
|
|
Point from,
|
|
|
|
Point to,
|
|
|
|
Point start,
|
|
|
|
Point cp1,
|
|
|
|
Point cp2,
|
|
|
|
Point end
|
|
|
|
)
|
|
|
|
```
|
|
|
|
|
|
|
|
Finds the intersection between a line segment from point `from` to point `to`
|
2021-10-17 17:34:55 +02:00
|
|
|
and a curve described by points `start`, `cp1`, `cp2, and `end\`.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
<Example part="utils_lineintersectscurve" caption="A Utils.lineIntersectsCurve() example" />
|
|
|
|
|
|
|
|
```js
|
|
|
|
let {
|
|
|
|
Point,
|
|
|
|
points,
|
|
|
|
Path,
|
|
|
|
paths,
|
|
|
|
Snippet,
|
|
|
|
snippets,
|
|
|
|
utils
|
|
|
|
} = part.shorthand();
|
|
|
|
|
|
|
|
points.A = new Point(10, 10);
|
|
|
|
points.Acp = new Point(310, 40);
|
|
|
|
points.B = new Point(110, 70);
|
|
|
|
points.Bcp = new Point(-210, 40);
|
|
|
|
points.E = new Point(20, -5);
|
|
|
|
points.D = new Point(100, 85);
|
|
|
|
paths.curve = new Path()
|
|
|
|
.move(points.A)
|
|
|
|
.curve(points.Acp, points.Bcp, points.B);
|
|
|
|
paths.line = new Path().move(points.E).line(points.D);
|
|
|
|
|
|
|
|
for (let p of utils.lineIntersectsCurve(
|
|
|
|
points.D,
|
|
|
|
points.E,
|
|
|
|
points.A,
|
|
|
|
points.Acp,
|
|
|
|
points.Bcp,
|
|
|
|
points.B
|
|
|
|
)) {
|
|
|
|
snippets[part.getId()] = new Snippet("notch", p);
|
|
|
|
}
|
|
|
|
```
|