{"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":{"integrity":"sha512-5RXAghb/GI+u96jzhXzHflA2qYgC/mXNsjUGXSlcPSQZHNe+xJSo32L3Kb7XD7tPrmYZOTed5F/7UaWNjY6lwg==","shasum":"ed9c86c72dca03e6539dc63c53f876e33d462dfa","tarball":"http://registry-npm.ywwl.com/points-on-curve/download/points-on-curve-1.0.0.tgz","fileCount":10,"unpackedSize":17319,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJiBAHGCRA9TVsSAnZWagAALWIP/0N/OGoNfBLkR+lGAgzJ\n9PUkt5QVJaPP++vt9IKEYq8lyvItyNPLMlgKya66atW17TpkZxW+1YonSqeP\n2qJwminRZ8krLsF1XtX7mMsmpBzvLh2+G4QKrXEYUDun6wIdLkD4L/d8oj11\n781h7WQkPiCYA+RH4d4zCAH9n8M9bowY3f6cBoENSFEbvm6KogecOkFXaiL0\noZ7WjKgAiTMYAqs93CL+LJe87Kd4FfEkyY2AZcaZGznMd0t2w8nRwppH4LSw\npaK90g9e73xpk0Px1OYKavD4vwh5YgD4NNvnFajplbZyLNC5VxO23KdiIOAw\neFVv2q2Tu4gAJ73tjXdohMXKQR2JMmuR86ooMkNWTDesfdfQTxVndE6RLky1\nB5zwMBIeMK+D/fW9hTAl8bvI+XgnkvS7aCcQdHGGWmyARb3L59QMOKjJMwXp\njiRR6ZuoujHsAXmrUgEFNzlrvJEefI3T0MTbogVLvnMslgQexPm32Jli2dp3\nufbYYPjShmHL9I0/5dlxRiX1Fd4laXVXJ+kL4L4IU2dUg/b+8LvptagG1jCj\nSibDa9DxawtrWpqwvQQsuQ5rBswas7xUD/SFwSm3nChYzs0G+Pq2hsy3Z0g/\nlm/wxwUKPyM1NJh4F2WXEcjdSOY0+39x3uoBLnhGSq3uJlerfchrv3tbscPd\nRKoH\r\n=c8Yr\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCs/2EKvsJpAYVFJrwQPF/npUcXRbzpqhTVlKn7L6zNogIgamSwVFLd0wVaSR+Kmi0vn35cmZ1ZMo1EqzWta4RaF5I="}],"size":5188,"noattachment":false,"key":"/points-on-curve/-/points-on-curve-1.0.0.tgz"},"_npmUser":{"name":"shihn","email":"preetshihn@gmail.com"},"directories":{},"maintainers":[{"name":"shihn","email":"preetshihn@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/points-on-curve_1.0.0_1644429766124_0.620069085525309"},"_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":1644429766275,"_cnpm_publish_time":1644429766275,"dist-tags":{"latest":"1.0.1"}}