{"_id":"points-on-curve","_rev":"4127086","name":"points-on-curve","description":"Estimate points on a bezier curve or a set of connexted bezier curves","dist-tags":{"latest":"1.0.1"},"maintainers":[{"name":"shihn","email":""}],"time":{"modified":"2026-03-01T18:25:33.000Z","created":"2020-04-10T21:01:03.255Z","1.0.1":"2023-09-23T20:22:30.501Z","1.0.0":"2022-02-09T18:02:46.275Z","0.2.0":"2020-04-14T22:30:32.582Z","0.1.1":"2020-04-13T06:35:00.848Z","0.1.0":"2020-04-11T20:26:38.117Z","0.0.1":"2020-04-10T21:01:03.255Z"},"users":{},"author":{"name":"Preet Shihn"},"repository":{"type":"git","url":"git+https://github.com/pshihn/bezier-points.git"},"versions":{"1.0.1":{"name":"points-on-curve","version":"1.0.1","description":"Estimate points on a bezier curve or a set of connexted bezier curves","main":"lib/index.js","module":"lib/index.js","types":"lib/index.d.ts","scripts":{"build":"rm -rf lib && tsc","test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/pshihn/bezier-points.git"},"keywords":["Bezier","graphics"],"author":{"name":"Preet Shihn"},"license":"MIT","bugs":{"url":"https://github.com/pshihn/bezier-points/issues"},"homepage":"https://github.com/pshihn/bezier-points#readme","devDependencies":{"typescript":"^4.5.5"},"gitHead":"00d0a7de7dc4b6e4aab70d670afa21c4a6c6b77a","_id":"points-on-curve@1.0.1","_nodeVersion":"18.12.1","_npmVersion":"8.19.2","dist":{"shasum":"03fcdc08e48e3bfdc7e8bd1d7ccd4d5f11e132c6","size":5132,"noattachment":false,"key":"/points-on-curve/-/points-on-curve-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/points-on-curve/download/points-on-curve-1.0.1.tgz"},"_npmUser":{"name":"shihn","email":"preetshihn@gmail.com"},"directories":{},"maintainers":[{"name":"shihn","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/points-on-curve_1.0.1_1695500550309_0.14023367942668918"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-09-23T20:22:30.501Z","publish_time":1695500550501,"_source_registry_name":"default","_cnpm_publish_time":1695500550501},"1.0.0":{"name":"points-on-curve","version":"1.0.0","description":"Estimate points on a bezier curve or a set of connexted bezier curves","main":"lib/index.js","module":"lib/index.js","types":"lib/index.d.ts","scripts":{"build":"rm -rf lib && tsc","test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/pshihn/bezier-points.git"},"keywords":["Bezier","graphics"],"author":{"name":"Preet Shihn"},"license":"MIT","bugs":{"url":"https://github.com/pshihn/bezier-points/issues"},"homepage":"https://github.com/pshihn/bezier-points#readme","devDependencies":{"typescript":"^4.5.5"},"gitHead":"a65a82cb19a1b8be4b13fabc174e5704837a4d32","_id":"points-on-curve@1.0.0","_nodeVersion":"14.18.3","_npmVersion":"6.14.15","dist":{"shasum":"ed9c86c72dca03e6539dc63c53f876e33d462dfa","size":5188,"noattachment":false,"key":"/points-on-curve/-/points-on-curve-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/points-on-curve/download/points-on-curve-1.0.0.tgz"},"_npmUser":{"name":"shihn","email":"preetshihn@gmail.com"},"directories":{},"maintainers":[{"name":"shihn","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/points-on-curve_1.0.0_1644429766124_0.620069085525309"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-02-09T18:02:53.752Z","publish_time":1644429766275,"_cnpm_publish_time":1644429766275},"0.2.0":{"name":"points-on-curve","version":"0.2.0","description":"Estimate points on a bezier curve or a set of connexted bezier curves","main":"lib/index.js","module":"lib/index.js","types":"lib/index.d.ts","scripts":{"build":"rm -rf lib && tsc","lint":"tslint -p tsconfig.json","test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/pshihn/bezier-points.git"},"keywords":["Bezier","graphics"],"author":{"name":"Preet Shihn"},"license":"MIT","bugs":{"url":"https://github.com/pshihn/bezier-points/issues"},"homepage":"https://github.com/pshihn/bezier-points#readme","devDependencies":{"tslint":"^6.1.1","typescript":"^3.8.3"},"gitHead":"48241476eb86307294f54913ccfb60a3e7338c56","_id":"points-on-curve@0.2.0","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"shasum":"7dbb98c43791859434284761330fa893cb81b4d1","size":5522,"noattachment":false,"key":"/points-on-curve/-/points-on-curve-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/points-on-curve/download/points-on-curve-0.2.0.tgz"},"maintainers":[{"name":"shihn","email":""}],"_npmUser":{"name":"shihn","email":"preetshihn@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/points-on-curve_0.2.0_1586903432428_0.03147317875806577"},"_hasShrinkwrap":false,"publish_time":1586903432582,"_cnpm_publish_time":1586903432582,"_cnpmcore_publish_time":"2021-12-17T02:50:21.206Z"},"0.1.1":{"name":"points-on-curve","version":"0.1.1","description":"Estimate points on a bezier curve or a set of connexted bezier curves","main":"lib/index.js","module":"lib/index.js","types":"lib/index.d.ts","scripts":{"build":"rm -rf lib && tsc","lint":"tslint -p tsconfig.json","test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/pshihn/bezier-points.git"},"keywords":["Bezier","graphics"],"author":{"name":"Preet Shihn"},"license":"MIT","bugs":{"url":"https://github.com/pshihn/bezier-points/issues"},"homepage":"https://github.com/pshihn/bezier-points#readme","devDependencies":{"tslint":"^6.1.1","typescript":"^3.8.3"},"gitHead":"a3851717b902dc1b93f6738c590455f06fa4d82c","_id":"points-on-curve@0.1.1","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"shasum":"2ed4e20138e84e3bc46a7f044b5e41dd875ae396","size":5479,"noattachment":false,"key":"/points-on-curve/-/points-on-curve-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/points-on-curve/download/points-on-curve-0.1.1.tgz"},"maintainers":[{"name":"shihn","email":""}],"_npmUser":{"name":"shihn","email":"preetshihn@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/points-on-curve_0.1.1_1586759700717_0.9900181259956877"},"_hasShrinkwrap":false,"publish_time":1586759700848,"_cnpm_publish_time":1586759700848,"_cnpmcore_publish_time":"2021-12-17T02:50:21.426Z"},"0.1.0":{"name":"points-on-curve","version":"0.1.0","description":"Estimate points on a bezier curve or a set of connexted bezier curves","main":"lib/index.js","module":"lib/index.js","types":"lib/index.d.ts","scripts":{"build":"rm -rf lib && tsc","lint":"tslint -p tsconfig.json","test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/pshihn/bezier-points.git"},"keywords":["Bezier","graphics"],"author":{"name":"Preet Shihn"},"license":"MIT","bugs":{"url":"https://github.com/pshihn/bezier-points/issues"},"homepage":"https://github.com/pshihn/bezier-points#readme","devDependencies":{"tslint":"^6.1.1","typescript":"^3.8.3"},"gitHead":"6bda64fc576dc7ac2f6bd685708219e14dfb2a4c","_id":"points-on-curve@0.1.0","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"shasum":"2c4cef65a05d81dde67a6f4e282603b7a56b0d75","size":5487,"noattachment":false,"key":"/points-on-curve/-/points-on-curve-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/points-on-curve/download/points-on-curve-0.1.0.tgz"},"maintainers":[{"name":"shihn","email":""}],"_npmUser":{"name":"shihn","email":"preetshihn@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/points-on-curve_0.1.0_1586636797996_0.12113682823191585"},"_hasShrinkwrap":false,"publish_time":1586636798117,"_cnpm_publish_time":1586636798117,"_cnpmcore_publish_time":"2021-12-17T02:50:21.704Z"},"0.0.1":{"name":"points-on-curve","version":"0.0.1","description":"Estimate points on a bezier curve or a set of connexted bezier curves","main":"lib/index.js","module":"lib/index.js","types":"lib/index.d.ts","scripts":{"build":"rm -rf lib && tsc","lint":"tslint -p tsconfig.json","test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/pshihn/bezier-points.git"},"keywords":["Bezier","graphics"],"author":{"name":"Preet Shihn"},"license":"MIT","bugs":{"url":"https://github.com/pshihn/bezier-points/issues"},"homepage":"https://github.com/pshihn/bezier-points#readme","devDependencies":{"tslint":"^6.1.1","typescript":"^3.8.3"},"gitHead":"e88a964a1122ffef96b8cc453cc414a6c80a8c1e","_id":"points-on-curve@0.0.1","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"shasum":"08746a0274ec28bfd8e8454745573deca3583225","size":3471,"noattachment":false,"key":"/points-on-curve/-/points-on-curve-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/points-on-curve/download/points-on-curve-0.0.1.tgz"},"maintainers":[{"name":"shihn","email":""}],"_npmUser":{"name":"shihn","email":"preetshihn@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/points-on-curve_0.0.1_1586552462508_0.42877750227986366"},"_hasShrinkwrap":false,"publish_time":1586552463255,"_cnpm_publish_time":1586552463255,"_cnpmcore_publish_time":"2021-12-17T02:50:21.898Z"}},"readme":"# points-on-curve\n\nThis package calculate the points on a curve with a certain tolerance. It can also simplify the shape to use fewer points. \nThis can really be useful when estimating lines/polygons for curves in WebGL or for Hit/Collision detections. \n\n## Install\n\nFrom npm\n\n```\nnpm install --save points-on-curve\n```\n\nThe package is distributed as an ES6 module. \n\n## API\n\n### pointsOnBezierCurves(points: Point[], tolerance?: number, distance?: number): Point[]\n\nYou pass in the points representing a bezier curve. Each point is an array of two numbers e.g. `[100, 123]`.\n\nThe points can also be a set of continuous curves where the last poing on the `Nth` curve acts as the first point of the next. \n\n```javascript\nimport { pointsOnBezierCurves } from 'points-on-curve';\n\nconst curve = [[70,240],[145,60],[275,90],[300,230]];\nconst points = pointsOnBezierCurves(curve);\n// plotPoints(points);\n```\n\n![points on bezier](https://user-images.githubusercontent.com/833927/79051836-45630300-7be7-11ea-8cb6-cba2695a4807.png)\n\nSame can be rendered with more **tolerance** (default value is 0.15):\n\n```javascript\nconst points = pointsOnBezierCurves(curve, 0.7);\n```\n![points on bezier with 0.7 tolerance](https://user-images.githubusercontent.com/833927/79051837-45fb9980-7be7-11ea-9583-52cf882e770e.png)\n\nNote that this method does not accept the number of points to render, but takes in a tolerance level which allows for better distribution of points. \n\nThe value of **tolerance** can be between 0 and 1. It is used to decide how many points are needed in a section of the curve. The algorithm determined the *flatness* of a section of the curve and compares it to the *tolerance* level, if less flat, the segment gets further divided into 2 segments. \n\n\n#### Simplifying path\n\nBased on the tolerance alone, this algorithm nicely provides enough points to represent a curve. It does not, however, efficiently get rid of unneeded points. The second *optional* argument in function, **distance** helps with that. If a `distance` value is provided, the method uses the [Ramer–Douglas–Peucker algorithm](https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm) to reduce the points. \n\n```javascript\nconst points = pointsOnBezierCurves(curve, 0.2, 0.15);\n```\n\nFollowing are the points generated with distance values of `0.15`, `0.75`, `1.5`, and `3.0`\n\n![points with 0.15d](https://user-images.githubusercontent.com/833927/79051853-53b11f00-7be7-11ea-8970-7cc3f7621142.png)\n![points with 0.75d](https://user-images.githubusercontent.com/833927/79051854-5449b580-7be7-11ea-9601-a1dd418b10d8.png)\n![points with 1.5d](https://user-images.githubusercontent.com/833927/79051855-5449b580-7be7-11ea-9ab4-139beb0faf11.png)\n![points with 3.0d](https://user-images.githubusercontent.com/833927/79051856-54e24c00-7be7-11ea-9f52-34e3ad9c81bd.png)\n\n### curveToBezier(pointsIn: Point[]): Point[]\n\nSometimes it's hard to think of shape as a set of cubic bezier curves, each curve with 2 controls points. It is simple to just think of them as a curve passing through a set of points. \n\nThis method turns those set of points to a set of points representing bezier curves.\n\n```javascript\nimport { curveToBezier } from 'points-on-curve/lib/curve-to-bezier.js';\n\nconst curvePoints = [\n  [20, 240],\n  [95, 69],\n  [225, 90],\n  [250, 180],\n  [290, 220],\n  [380, 80],\n];\nconst bcurve = curveToBezier(curvePoints);\n// .. Plot bcurve\n```\n![Curve through points](https://user-images.githubusercontent.com/833927/79051797-12b90a80-7be7-11ea-92d2-5cb79adcbe30.png)\n\nNow that we have bezier points, these could be passed to `pointsOnBezierCurves` function to get the points on the curve\n\n![Curve through points](https://user-images.githubusercontent.com/833927/79051798-1351a100-7be7-11ea-8465-959a22b72371.png)\n\n\n## License\n[MIT License](https://github.com/pshihn/bezier-points/blob/master/LICENSE)\n\n","_attachments":{},"homepage":"https://github.com/pshihn/bezier-points#readme","bugs":{"url":"https://github.com/pshihn/bezier-points/issues"},"license":"MIT"}