JSCAD User Group

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Bezier tubes

    Development Discussions
    2
    2
    397
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • SimonClark
      SimonClark last edited by SimonClark

      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.

      tube([
      	[8,2,12],
      	[8,-6,12],
      	[8,0,0],
      	[-8,4,2],
      	[-8,-2,2]
      ]);
      
      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 = tubeCurve.at(progress);
      				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.

      z3dev 1 Reply Last reply Reply Quote 0
      • z3dev
        z3dev @SimonClark last edited by

        @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!)

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Powered by NodeBB | Contributors