Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/w8r/bezier-intersect
Set of functions to find intersections between lines and rectangles and Bezier curves of order 2 and 3
https://github.com/w8r/bezier-intersect
algorithm bezier curves geometry geometry2d intersection
Last synced: about 2 hours ago
JSON representation
Set of functions to find intersections between lines and rectangles and Bezier curves of order 2 and 3
- Host: GitHub
- URL: https://github.com/w8r/bezier-intersect
- Owner: w8r
- Created: 2018-01-18T18:12:00.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-18T14:23:42.000Z (over 6 years ago)
- Last Synced: 2024-11-10T22:48:35.706Z (7 days ago)
- Topics: algorithm, bezier, curves, geometry, geometry2d, intersection
- Language: JavaScript
- Homepage:
- Size: 17.6 KB
- Stars: 42
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# bezier-intersect [![npm version](https://badge.fury.io/js/bezier-intersect.svg)](https://badge.fury.io/js/bezier-intersect) [![build](https://travis-ci.org/w8r/bezier-intersect.svg?branch=master)](https://travis-ci.org/w8r/bezier-intersect)
Set of functions to find intersections between lines and rectangles and Bezier curves of order 2 and 3. Based on [thelonious/js-intersections](https://github.com/thelonious/js-intersections/), but with the abstractions removed and some performance tweaking.
## Install
```
npm i -S bezier-intersect
``````js
import {
quadBezierLine,
cubicBezierLine,
quadBezierAABB,
cubicBezierAABB
} from 'bezier-intersect';
``````html
var res = [];
bezierIntersect.quadBezierLine(..., res);
console.log(res);```
## API
### `quadBezierLine(ax, ay, cx, cy, bx, by, l1x, l1y, l2x, l2y, [result:Array]):number`
Calculates the intersection points between the quadratic Bezier curve and line segment. If `result` is passed, returns the exact number of intersections, and stores them in `result` as `[x, y, x, y]`. If not - stops at the first intersection and returns `1` or `0` if there are no intersections.
### `quadBezierAABB(ax, ay, cx, cy, bx, by, minx, miny, maxx, maxy, [result:Array]):number`
Calculates the intersection points between the quadratic Bezier curve and axis-aligned box. If `result` is passed, returns the exact number of intersections, and stores them in `result` as `[x, y, x, y]`. If not - stops at the first intersection and returns `1` or `0` if there are no intersections.
### `cubicBezierLine(ax, ay, c1x, c1y, c2x, c2y, bx, by, l1x, l1y, l2x, l2y, [result:Array]):number`
Calculates the intersection points between the cubic Bezier curve and line segment. If `result` is passed, returns the exact number of intersections, and stores them in `result` as `[x, y, x, y]`. If not - stops at the first intersection and returns `1` or `0` if there are no intersections.
### `cubicBezierAABB(ax, ay, c1x, c1y, c2x, c2y, bx, by, minx, miny, maxx, maxy, [result:Array]):number`
Calculates the intersection points between the cubic Bezier curve and axis-aligned box. If `result` is passed, returns the exact number of intersections, and stores them in `result` as `[x, y, x, y]`. If not - stops at the first intersection and returns `1` or `0` if there are no intersections.
## TODO
- [ ] More tests
- [ ] Bezier/Polygon
- [ ] Bezier/Ellipse/Circle## License
MIT