2021-10-17 18:26:00 +02:00
|
|
|
---
|
2022-10-01 22:20:43 +02:00
|
|
|
title: utils.curveIntersectsY()
|
2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-12-05 15:25:06 -08:00
|
|
|
The `utils.curveIntersectsY()` function finds the point(s) where a curve
|
2022-10-01 22:20:43 +02:00
|
|
|
intersects a given Y-value.
|
|
|
|
|
|
|
|
## Signature
|
|
|
|
|
2021-08-25 16:09:31 +02:00
|
|
|
```js
|
|
|
|
array | Point | false utils.curveIntersectsY(
|
|
|
|
Point start,
|
|
|
|
Point cp1,
|
|
|
|
Point cp2,
|
|
|
|
Point end,
|
|
|
|
float y)
|
|
|
|
```
|
|
|
|
|
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
|
|
|
|
<Example caption="A Utils.curveIntersectY() 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
|
|
|
|
2022-10-01 22:20:43 +02:00
|
|
|
points.start = new Point(10, 45)
|
|
|
|
points.cp1 = new Point(50, 10)
|
|
|
|
points.cp2 = new Point(0, 80)
|
|
|
|
points.end = new Point(110, 70)
|
|
|
|
|
|
|
|
paths.curve = new Path()
|
|
|
|
.move(points.start)
|
|
|
|
.curve(points.cp1, points.cp2, points.end)
|
|
|
|
|
|
|
|
for (let y of [40, 50]) {
|
|
|
|
points["from" + y] = new Point(10, y)
|
|
|
|
points["to" + y] = new Point(110, y)
|
|
|
|
paths["line" + y] = new Path()
|
|
|
|
.move(points["from" + y])
|
|
|
|
.line(points["to" + y])
|
|
|
|
.addClass("lining dashed")
|
|
|
|
}
|
|
|
|
|
|
|
|
snippets.i50 = new Snippet(
|
|
|
|
"notch",
|
|
|
|
utils.curveIntersectsY(points.start, points.cp1, points.cp2, points.end, 50)
|
|
|
|
)
|
|
|
|
|
|
|
|
for (let p of utils.curveIntersectsY(
|
|
|
|
points.start,
|
|
|
|
points.cp1,
|
|
|
|
points.cp2,
|
|
|
|
points.end,
|
|
|
|
40
|
|
|
|
))
|
|
|
|
snippets[p.x] = new Snippet("notch", p)
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-01 22:20:43 +02:00
|
|
|
return part
|
2021-08-25 16:09:31 +02:00
|
|
|
}
|
2022-10-01 22:20:43 +02:00
|
|
|
```
|
|
|
|
</Example>
|
|
|
|
|
|
|
|
## Notes
|
|
|
|
|
|
|
|
This is a low-level (and faster) variant
|
|
|
|
of [`Path.intersectsY()`](/reference/api/path/intersectsy).
|
|
|
|
Instead of a path, you describe a single curve by passing the four
|
|
|
|
points that describes it.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
|