{"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":{"integrity":"sha512-AncNOQnNKzCJBGPW/+PLFCLvWMFoemwR+1D1QTPY8HFhiz42sNtRClR52AuejId3Rv6p3SvUogfJGtygk9MaYg==","shasum":"08746a0274ec28bfd8e8454745573deca3583225","tarball":"http://registry-npm.ywwl.com/points-on-curve/download/points-on-curve-0.0.1.tgz","fileCount":8,"unpackedSize":11254,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJekN6PCRA9TVsSAnZWagAAf/wP/iNP1XYQAGx/igdwzO7Z\nQY+/bkBAS8ZHuMRr9zLSf7bYdTbEE23UeGL6Rb5u2QeylONmxUk0Hb5TI0/y\n2slyN51q3ZhHrJONEvUFurQLBRI9tJfU0YO+CPx7zcfzQCRj7r43nAzxjjZh\nuA5Ms4HxATSj8oIgTSzjOiH8zZ4quYFH146ceoXuQkJGftqOsQtInbMaHJoF\n04Rp21qUxZ1eV+ZQPHysgotbrxKNZO82hanEhtwc0Fk39opVKbo7fRXSvf+v\n0MKZoTEN22oc6YAdqkHD8RvZDKUmZXO0dPmpxlRPGjNoZ2hi/LETzfiIgulN\nl9ctrSDMLpLDWuyFlGrsLdbylH2KqaxhRUp8a0fKL8xaoVzBQCvD2Hvr7C7+\nTNnjqqfr6VXZOBDnHfW48t1tc7kxJ2tlwrraY8nthu5k8b1iWdVAGz9KFemW\nje7jdoraUe9H0DlI/YEbwJ5DdQp+aorJYDBO1K0m/yH/A5eJpLY14aUyGOGg\ncIKlhIuLiYEHYTG4tP8xBFp8lHaR/pmzFjnmagwMbW5qFMUGSySQCBGc7xmi\n4Pdn/3XULnZx2kvSMsKpG44rozv5zZfZJ+zlm6THbmzsk4zFIkLYSP8iuiZe\nwXHjEmvHWRMcJqCUdIYGKd1jgZvAuhK07eKmaggcNg+ITxNfT2GiC7bs9eNJ\nfZAv\r\n=Dl5P\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICAFenQuLPRdz58dZakGVkA3kfscGmIUXyuZZICvV66HAiAAihdm1ikkhAmebukFUJpUER0Pbb3dQM48MoaEI1EMqQ=="}],"size":3471,"noattachment":false,"key":"/points-on-curve/-/points-on-curve-0.0.1.tgz"},"maintainers":[{"name":"shihn","email":"preetshihn@gmail.com"}],"_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,"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","publish_time":1586552463255,"_cnpm_publish_time":1586552463255,"dist-tags":{"latest":"1.0.1"}}