JSCAD User Group
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Bezier tubes

    Scheduled Pinned Locked Moved Development Discussions
    2 Posts 2 Posters 993 Views 1 Watching
    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.
    • SimonClarkS Offline
      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.

      z3devZ 1 Reply Last reply Reply Quote 0
      • z3devZ Offline
        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

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post
        Powered by NodeBB | Contributors