SVG arc to cubic bezier
A function that takes an SVG arc curve as input, and maps it to
one or more cubic bezier curves.
I extracted the a2c
function from
SVG path, as I wanted to use it on its own.
All credit, thanks and respect goes to:
It blew my mind. Thank you!
Installation
npm install svg-arc-to-cubic-bezier
Usage
import arcToBezier from 'svg-arc-to-cubic-bezier';
const previousPoint = { x: 100, y: 100 }
const currentPoint = {
x: 700,
y: 100,
curve: {
type: 'arc',
rx: 300,
ry: 200,
largeArcFlag: 30,
sweepFlag: 0,
xAxisRotation: 0,
},
};
const curves = arcToBezier({
px: previousPoint.x,
py: previousPoint.y,
cx: currentPoint.x,
cy: currentPoint.y,
rx: currentPoint.curve.rx,
ry: currentPoint.curve.ry,
xAxisRotation: currentPoint.curve.xAxisRotation,
largeArcFlag: currentPoint.curve.largeArcFlag,
sweepFlag: currentPoint.curve.sweepFlag,
});
curves.forEach( c => console.log( c ));