1 line
14 KiB
Plaintext
1 line
14 KiB
Plaintext
|
|
{"version":3,"file":"CurveExtras.cjs","sources":["../../src/curves/CurveExtras.js"],"sourcesContent":["import { Curve, Vector3 } from 'three'\n\n/**\n * A bunch of parametric curves\n *\n * Formulas collected from various sources\n * http://mathworld.wolfram.com/HeartCurve.html\n * http://en.wikipedia.org/wiki/Viviani%27s_curve\n * http://www.mi.sanu.ac.rs/vismath/taylorapril2011/Taylor.pdf\n * https://prideout.net/blog/old/blog/index.html@p=44.html\n */\n\n// GrannyKnot\n\nclass GrannyKnot extends Curve {\n getPoint(t, optionalTarget = new Vector3()) {\n const point = optionalTarget\n\n t = 2 * Math.PI * t\n\n const x = -0.22 * Math.cos(t) - 1.28 * Math.sin(t) - 0.44 * Math.cos(3 * t) - 0.78 * Math.sin(3 * t)\n const y = -0.1 * Math.cos(2 * t) - 0.27 * Math.sin(2 * t) + 0.38 * Math.cos(4 * t) + 0.46 * Math.sin(4 * t)\n const z = 0.7 * Math.cos(3 * t) - 0.4 * Math.sin(3 * t)\n\n return point.set(x, y, z).multiplyScalar(20)\n }\n}\n\n// HeartCurve\n\nclass HeartCurve extends Curve {\n constructor(scale = 5) {\n super()\n\n this.scale = scale\n }\n\n getPoint(t, optionalTarget = new Vector3()) {\n const point = optionalTarget\n\n t *= 2 * Math.PI\n\n const x = 16 * Math.pow(Math.sin(t), 3)\n const y = 13 * Math.cos(t) - 5 * Math.cos(2 * t) - 2 * Math.cos(3 * t) - Math.cos(4 * t)\n const z = 0\n\n return point.set(x, y, z).multiplyScalar(this.scale)\n }\n}\n\n// Viviani's Curve\n\nclass VivianiCurve extends Curve {\n constructor(scale = 70) {\n super()\n\n this.scale = scale\n }\n\n getPoint(t, optionalTarget = new Vector3()) {\n const point = optionalTarget\n\n t = t * 4 * Math.PI // normalized to 0..1\n const a = this.scale / 2\n\n const x = a * (1 + Math.cos(t))\n const y = a * Math.sin(t)\n const z = 2 * a * Math.sin(t / 2)\n\n return point.set(x, y, z)\n }\n}\n\n// KnotCurve\n\nclass KnotCurve extends Curve {\n getPoint(t, optionalTarget = new Vector3()) {\n const point = optionalTarget\n\n t *= 2 * Math.PI\n\n const R = 10\n const s = 50\n\n const x = s * Math.sin(t)\n const y = Math.cos(t) * (R + s * Math.cos(t))\n const z = Math.sin(t) * (R + s * Math.cos(t))\n\n return point.set(x, y, z)\n }\n}\n\n// HelixCurve\n\nclass HelixCurve extends Curve {\n getPoint(t, optionalTarget = new Vector3()) {\n const point = optionalTarget\n\n const a = 30 // radius\n const b = 150 // height\n\n const t2 = (2 * Math.PI * t * b) / 30\n\n const x = Math.cos(t2) * a\n const y = Math.sin(t2) * a\n const z = b * t\n\n return point.set(x, y, z)\n }\n}\n\n// TrefoilKnot\n\nclass TrefoilKnot extends Curve {\n constructor(scale = 10) {\n super()\n\n this.scale = scale\n }\n\n getPoint(t, optionalTarget = new Vector3()) {\n const point = optionalTarget\n\n t *= Math.PI * 2\n\n const x = (2 + Math.cos(3 * t)) * Math.cos(2 * t)\n const y = (2 + Math.cos(3 * t)) * Math.sin(2 * t)\n const z = Math.sin(3 * t)\n\n return point.set(x, y, z).multiplyScalar(this.scale)\n }\n}\n\n// TorusKnot\n\nclass TorusKnot extends Curve {\n constructor(scale = 10) {\n super()\n\n this.scale = scale\n }\n\n getPoint(t, optionalTarget = new Vector3()) {\n const point = optionalTarget\n\n const p = 3\n const q = 4\n\n t *= Math.PI * 2\n\n const x = (2 + Math.cos(q * t)) * Math.cos(p * t)\n const y = (2 + Math.cos(q * t)) * Math.sin(p * t)\n const z = Math.sin(q * t)\n\n return point.set(x, y, z).multiplyScalar(this.scale)\n }\n}\n\n// CinquefoilKnot\n\nclass CinquefoilKnot extends Curve {\n constructor(scale = 10) {\n super()\n\n this.scale = scale\n }\n\n getPoint(t, optionalTarget = new Vector3()) {\n const point = optionalTarget\n\n const p = 2\n const q = 5\n\n t *= Math.PI * 2\n\n const x = (2 + Math.cos(q * t)) * Math.cos(p * t)\n const y = (2 + Math.cos(q * t)) * Math.sin(p * t)\n const z = Math.sin(q * t)\n\n return point.set(x, y, z).multiplyScalar(this.scale)\n }\n}\n\n// TrefoilPolynomialKnot\n\nclass TrefoilPolynomialKnot extends
|