2021-10-17 18:26:00 +02:00
|
|
|
---
|
2022-10-01 22:20:43 +02:00
|
|
|
title: utils.curveIntersectsX()
|
2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-01 22:20:43 +02:00
|
|
|
The `utils.curveIntersectsX()` function finds the point(s) where a curve
|
|
|
|
intersects a given X-value.
|
|
|
|
|
|
|
|
## Signature
|
|
|
|
|
2021-08-25 16:09:31 +02:00
|
|
|
```js
|
|
|
|
array | Point | false utils.curveIntersectsX(
|
2023-04-04 22:04:53 -07:00
|
|
|
Point start,
|
2021-08-25 16:09:31 +02:00
|
|
|
Point cp1,
|
|
|
|
Point cp2,
|
|
|
|
Point end,
|
|
|
|
float x)
|
|
|
|
```
|
|
|
|
|
2022-02-19 08:04:25 +01:00
|
|
|
This returns `false` if no intersections are found,
|
|
|
|
a [Point](/reference/api/point) object if
|
|
|
|
a single intersection is found, and an array
|
|
|
|
of [Point](/reference/api/point) objects if
|
2021-08-25 16:09:31 +02:00
|
|
|
multiple intersections are found.
|
|
|
|
|
2022-10-01 22:20:43 +02:00
|
|
|
## Example
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-01 22:20:43 +02:00
|
|
|
<Example caption="A Utils.curveIntersectX() example">
|
2021-08-25 16:09:31 +02:00
|
|
|
```js
|
2022-10-01 22:20:43 +02:00
|
|
|
({ Point, points, Path, paths, Snippet, snippets, utils, part }) => {
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2025-04-18 19:19:20 +02:00
|
|
|
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])
|
|
|
|
.addClass("lining dashed")
|
2021-08-25 16:09:31 +02:00
|
|
|
}
|
2025-04-18 19:19:20 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
return part
|
|
|
|
}
|
|
|
|
|
2022-10-01 22:20:43 +02:00
|
|
|
```
|
|
|
|
</Example>
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
|
2022-10-01 22:20:43 +02:00
|
|
|
## Notes
|
|
|
|
|
|
|
|
This is a low-level (and faster) variant
|
|
|
|
of [`Path.intersectsX()`](/reference/api/path/intersectsx).
|
|
|
|
Instead of a path, you describe a single curve by passing the four
|
|
|
|
points that describes it.
|
2025-04-18 19:19:20 +02:00
|
|
|
```
|