Thursday, January 21, 2010

OpenSCAD Tip: Linear and Rotational Extrusions


Todays OpenSCAD tips and tricks starts with a circle that looks like a hexgon, but we will fix that later.
circle(r = 1);



Next, translate the circle along the X-axis.
translate([2, 0, 0])
circle(r = 1);


Now we can perform a linear extrude to produce a cylinder.
linear_extrude(height = 10, center = true, convexity = 10, twist = 0)
translate([2, 0, 0])
circle(r = 1);



The twist parameter appears to be left handed and is in units of degrees. A parameter of twist=360 will extrude one full rotation around the Z-Axis.
linear_extrude(height = 10, center = true, convexity = 10, twist = -100)
translate([2, 0, 0])
circle(r = 1);



Here is a twist of 100 degrees.
linear_extrude(height = 10, center = true, convexity = 10, twist = 100)
translate([2, 0, 0])
circle(r = 1);



A -500 degree twist shows how the 2d projection on the X-Y Plane is swept around the Z-Axis. The extrusion of the 2D shape is not perpendicular to the path of extrusion.
linear_extrude(height = 10, center = true, convexity = 10, twist = -500)
translate([2, 0, 0])
circle(r = 1);



If center = false the extrusion will start at the position of the original circle. If center = true then after extrusion the solid will be centered after extrusion.
linear_extrude(height = 10, center = false, convexity = 10, twist = -500)
translate([2, 0, 0])
circle(r = 1);



The shape of the circle can be improved by setting one of the special parameters $fn, $fs, and $fa. $fn is the number of fragments, $fs is the size of the fragments and $fa is the angle of the fragments.
linear_extrude(height = 10, center = false, convexity = 10, twist = 360)
translate([2, 0, 0])
circle(r = 1, $fn=100);



The shape of the extrusion can be improved by setting the $fn parameter of the extrude and this value is passed to the shape of the circle.
linear_extrude(height = 10, center = false, convexity = 10, twist = 360, $fn=100)
translate([2, 0, 0])
circle(r = 1);



The slices parameter is similar to the $fn special variable, expect it does not apply to the 2D shape.
linear_extrude(height = 10, center = false, convexity = 10, twist = 360, slices=100)
translate([2, 0, 0])
circle(r = 1);



A rotational extrusion of the circle will produce a torus.
rotate_extrude(convexity = 10)
translate([2, 0, 0])
circle(r = 1);



Similarly to a linear extrude, the rotational mesh results can be refined.
rotate_extrude(convexity = 10)
translate([2, 0, 0])
circle(r = 1, $fn=100);



Further refinement is possible and increases the amount of time required to compile and render the model.
rotate_extrude(convexity = 10, $fn=100)
translate([2, 0, 0])
circle(r = 1, $fn=100);

The convexity parameter is best explained by the following image.

The 2D shape in black has a convexity of 4 because a ray indicated in red may intersect the shape at most 4 times. Correction from Clifford Wolf, "To determine the convexity number one must only need to count the number of front or backsides a ray intersects - but not both." Therefore this example has a convexity of  2 and a circle has a convexity of 1. A 3D shape could be thought of in a similar way. Setting the convexity=10 unless you have a problem seems to be the easiest solution.

The OpenSCAD manual has been updated to include these examples.

Hopefully in the future there will be a way to produce helical sweeps so threaded parts such as worm gears can be produced.

3 comments:

Anonymous said...

Excellent tutorial.

obobo said...

Is there a parameter to modify the helix_radius formed by 'twist'?

I Heart Robotics said...

translate([2, 0, 0])
sets the radius of the helix