What is @turf/bezier-spline?
@turf/bezier-spline is a module in the Turf.js library that allows you to create smooth Bezier spline curves from a set of points. This is particularly useful in geographic information systems (GIS) for creating smooth paths or routes on a map.
What are @turf/bezier-spline's main functionalities?
Create Bezier Spline from Points
This feature allows you to create a smooth Bezier spline curve from a set of points. The `resolution` option controls the number of points in the resulting spline, and `sharpness` controls the curvature.
const turf = require('@turf/turf');
const points = turf.lineString([
[-75.343, 39.984],
[-75.534, 39.123],
[-75.123, 39.543],
[-75.534, 39.123],
[-75.343, 39.984]
]);
const options = { resolution: 10000, sharpness: 0.85 };
const bezierSpline = turf.bezierSpline(points, options);
console.log(JSON.stringify(bezierSpline));
Other packages similar to @turf/bezier-spline
bezier-js
bezier-js is a library for working with Bezier curves in JavaScript. It provides a wide range of functionalities for creating and manipulating Bezier curves, but it is not specifically tailored for geographic data like @turf/bezier-spline.
d3-shape
d3-shape is a part of the D3.js library that provides tools for creating and manipulating shapes, including Bezier curves. While it is very powerful and flexible, it is more general-purpose and not specifically designed for GIS applications.
paper
Paper.js is a vector graphics scripting framework that runs on top of the HTML5 Canvas. It provides a lot of functionalities for working with vector graphics, including Bezier curves. However, it is more focused on graphic design rather than GIS.
@turf/bezier-spline
bezierSpline
Takes a line and returns a curved version
by applying a Bezier spline
algorithm.
The bezier spline implementation is by Leszek Rybicki.
Parameters
Examples
var line = turf.lineString([
[-76.091308, 18.427501],
[-76.695556, 18.729501],
[-76.552734, 19.40443],
[-74.61914, 19.134789],
[-73.652343, 20.07657],
[-73.157958, 20.210656]
]);
var curved = turf.bezierSpline(line);
var addToMap = [line, curved]
curved.properties = { stroke: '#0F0' };
Returns Feature<LineString> curved line
This module is part of the Turfjs project, an open source module collection dedicated to geographic algorithms. It is maintained in the Turfjs/turf repository, where you can create PRs and issues.
Installation
Install this single module individually:
$ npm install @turf/bezier-spline
Or install the all-encompassing @turf/turf module that includes all modules as functions:
$ npm install @turf/turf