1
0
Fork 0
freesewing/markdown/dev/reference/api/utils/curveintersectsx/en.md
Joost De Cock b34a2ee2ed feat: Flat import of markdown repo
This is a flat (without history) import of (some of) the content
from our markdown module.

We've imported this without history because the repo contains our
blog posts and showcases posts content prior to porting them to strapi.

Since this contains many images, it would balloon the size of this repo
to import the full history.

Instead, please refer to the history of the (archived) markdown repo
at: https://github.com/freesewing/markdown
2021-08-25 16:09:31 +02:00

72 lines
1.5 KiB
Markdown

---
title: curveIntersectsX()
---
```js
array | Point | false utils.curveIntersectsX(
Point start,
Point cp1,
Point cp2,
Point end,
float x)
```
Finds the point(s) where a curve intersects a given X-value.
This is a low-level variant
of [`Path.intersectsX()`](/en/docs/developer/api/path/#pathintersectsx).
Instead of a path, you describe a single curve by passing the four
points that describes it.
This returns `false` if no intersections are found,
a [Point](/en/docs/developer/api/point/) object if
a single intersection is found, and an array
of [Point](/en/docs/developer/api/point/) objects if
multiple intersections are found.
<Example part="utils_curveintersectsx" caption="A Utils.curveIntersectX() example" />
```js
let {
Point,
points,
Path,
paths,
utils,
snippets,
Snippet
} = part.shorthand();
points.start = new Point(10, 15);
points.cp1 = new Point(80, 10);
points.cp2 = new Point(-50, 80);
points.end = new Point(110, 70);
paths.curve = new Path()
.move(points.start)
.curve(points.cp1, points.cp2, points.end);
for (let x of [30, 40]) {
points["from" + x] = new Point(x, 10);
points["to" + x] = new Point(x, 80);
paths["line" + x] = new Path()
.move(points["from" + x])
.line(points["to" + x])
.attr("class", "lining dashed");
}
snippets.i40 = new Snippet(
"notch",
utils.curveIntersectsX(points.start, points.cp1, points.cp2, points.end, 40)
);
for (let p of utils.curveIntersectsX(
points.start,
points.cp1,
points.cp2,
points.end,
30
))
snippets[p.y] = new Snippet("notch", p);
```