Bezier tubes

  • Screen Shot 2020-07-14 at 10.25.07 AM.png
    Updated my bezier implementation, and I wanted to share. :).

    It can now handle an arbitrary number of control points, and an arbitrary number of dimensions. Also allows for getting the tangential vector at any point along the curve.

    function tube(bezierControlPoints) {
    	let circ = circle({radius: 1, segments:32});
    	let circPoints = geometry.geom2.toPoints(circ);
    	let tubeSlice = slice.fromPoints(circPoints);
    	var tubeCurve = math.bezier.create(bezierControlPoints);
    	let tube = extrusions.extrudeFromSlices({
    			numberOfSlices: 60,
    			isCapped: true,
    			callback: function (progress, count, base) {
    				let position =;
    				let tangent = tubeCurve.tangentAt(progress);
    				let rotation = fromVectors(math.vec3.fromArray([0,0,1]),math.vec3.fromArray(tangent));
    				let translation = math.mat4.fromTranslation(position);
    				let newslice = slice.transform(math.mat4.multiply(translation, rotation), base);
    				return newslice
    		}, tubeSlice);
    	return tube;

    My rotation matrix from vectors code is a little funky when it's near 180 degrees, but otherwise, pretty happy with it.

  • @SimonClark this is cool. thanks for sharing.

    FYI, this functionality will behave far better after the next update, which folds full numeric precision back into the library. (And 10X improved speed is included for free!)

Log in to reply