UNPKG

shape-points

Version:

Generate points for simple shapes and curves: arcs, rectangles, rounded rectangles, circles, ellipses, bezierCurveTo, bezierCurveThrough (i.e., bezier curves through specific points)

80 lines (60 loc) 2.74 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: quadraticCurveTo.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: quadraticCurveTo.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>/** * calculate points in a quadratic curve * @module shape-points/quadraticCurveTo * @param {number} x1 - starting point * @param {number} y1 * @param {number} cp1x - control point * @param {number} cp1y * @param {number} x2 - ending point * @param {number} y2 * @returns {array} [x1, y1, x2, y2, ... xn, yn] */ export function quadraticCurveTo(x1, y1, cp1x, cp1y, x2, y2, pointsInArc) { pointsInArc = pointsInArc || 5 const points = [] const interval = 1 / pointsInArc for (let t = 0; t &lt;= 1; t += interval) { const B0_t = Math.pow(1 - t, 2), B1_t = 2 * t * (1 - t), B2_t = Math.pow(t, 2) points.push( (B0_t * x1) + (B1_t * cp1x) + (B2_t * x2), (B0_t * y1) + (B1_t * cp1y) + (B2_t * y2) ) } return points }</code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-shape-points.html">shape-points</a></li><li><a href="module-shape-points_arc.html">shape-points/arc</a></li><li><a href="module-shape-points_bezierCurveThrough.html">shape-points/bezierCurveThrough</a></li><li><a href="module-shape-points_bezierCurveTo.html">shape-points/bezierCurveTo</a></li><li><a href="module-shape-points_circle.html">shape-points/circle</a></li><li><a href="module-shape-points_ellipse.html">shape-points/ellipse</a></li><li><a href="module-shape-points_line.html">shape-points/line</a></li><li><a href="module-shape-points_quadraticCurveTo.html">shape-points/quadraticCurveTo</a></li><li><a href="module-shape-points_rect.html">shape-points/rect</a></li><li><a href="module-shape-points_roundedRect.html">shape-points/roundedRect</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Tue Mar 29 2022 14:31:03 GMT-0700 (Pacific Daylight Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>