Here we’ll use the LatheGeometry
class to rotate a parabola around a line perpendicular to its axis. The parabola is defined by the function for some constant . Three points are sufficient to determine the value of . Given the points , , and , we have , hence . We bound the parabola by the points and .
We use the parameter to indicate the axis of rotation. If is negative, the rotation axis is (to the left of the curve) and the resulting surface is concave. Alternatively, if is nonnegative, the rotation axis is (to the right of the curve) and the resulting surface is convex. 1
Note that the surface changes between convex and concave when the value of changes sign. The user uses the slider to set the value of whereas the value of is set by the program to the constant 8.
The following function generates the surface geometry. Since LatheGeometry
rotates around the y-axis (), it’s necessary to translate the curve if is negative (line 5), or translate and reflect the curve if is nonnegative (line 7).
function createQuadBandGeometry(x1, y1, X, density=100, segments=12) { let a = x1 / (y1 * y1); let f; if (X < 0) f = (y) => a * y * y - X; else f = (y) => -(a * y * y - (X + x1)); let ys = linspace(-y1, y1, density); let xs = ys.map(f); let vecs = []; for (let i = 0; i < ys.length; i++) vecs.push(new THREE.Vector2(xs[i], ys[i])); return new THREE.LatheGeometry(vecs, segments); }
The utility function linspace(a, b, n)
returns an array of n evenly-spaced values between a and b, where we assume a < b and n > 1.
linspace(a, b, n) { let res = []; let inc = (b - a) / (n - 1); for (let i = 0; i < n; i++) res.push(a + i * inc); return res; }
LatheGeometry
requires the entire curve to lie on the same side of the axis of rotation and so the rotation axis must lie to its left or its right. ↩