Bezier Curve Extension
This plugin provides three extension methods for Bezier curves.
Install with npm
npm install @jiaminghi/bezier-curve
Examples
bezierCurve
const bezierCurve = [
[20, 20],
[
[100, 20],[100, 80],[180,80]
],
]
bezierCurve in SVG
bezierCurveToPolyline
function bezierCurveToPolyline (bezierCurve, precision = 5) {
}
const precision = 5
const polyline = bezierCurveToPolyline(bezierCurve, precision)
polyline in SVG
Notice
- The calculation result of bezierCurveToPolyline consists of N points, and N depends on the precision you set.
- Recommended precision is 5-10.
- If the setting precision is less than 1 or too large, the calculation result may be abnormal.
- Sometimes it is impossible to achieve precision
getBezierCurveLength
export function getBezierCurveLength (bezierCurve, precision = 5) {
}
const length = bezierCurveToPolyline(bezierCurve)
polyline
const polyline = [
[20, 70],
[50, 30],
[100, 70],
[150, 30],
[180, 70]
]
polyline in SVG
polylineToBezierCurve
function polylineToBezierCurve (polyline, close = false, offsetA = 0.25, offsetB = 0.25) {
}
const bezierCurve = polylineToBezierCurve(polyline)
const closedBezierCurve = polylineToBezierCurve(polyline, true)
bezierCurve in SVG
closedBezierCurve in SVG