OpenSCAD User Manual/2D to 3D Extrusion
|
|
The text in its current form is incomplete. |
It is possible to use extrusion commands to convert 2D objects to 3D objects. This can be done with the built-in 2D primitives, like squares and circles, but also with arbitrary polygons.
Linear Extrude
Linear Extrusion is a modeling operation that takes a 2D polygon as input and extends it in the third dimension. This way a 3D shape is created.
Usage
linear_extrude(height = fanwidth, center = true, convexity = 10, twist = -fanrot, slices = 20) {...}
(You must use parameter names due to a backward compatability issue) (NB: The units of the Z-extrusion height are in millimeters)
If the extrusion fails for a non-trival 2D shape, try setting the convexity parameter (default is not 10, but 10 is a "good" value to try) See explanation further down.
Twist
Twist is the number of degrees of through which the shape is extruded. Setting the parameter twist = 360 will extrude through one revolution. The twist direction follows the left hand rule.
0° of Twist
linear_extrude(height = 10, center = true, convexity = 10, twist = 0) translate([2, 0, 0]) circle(r = 1);
-100° of Twist
linear_extrude(height = 10, center = true, convexity = 10, twist = -100) translate([2, 0, 0]) circle(r = 1);
100° of Twist
linear_extrude(height = 10, center = true, convexity = 10, twist = 100) translate([2, 0, 0]) circle(r = 1);
-500° of Twist
linear_extrude(height = 10, center = true, convexity = 10, twist = -500) translate([2, 0, 0]) circle(r = 1);
Center
Center determines if the object is centered after extrusion, so it does not extrude up and down from the center as you might expect.
center = true
linear_extrude(height = 10, center = true, convexity = 10, twist = -500) translate([2, 0, 0]) circle(r = 1);
center = false
linear_extrude(height = 10, center = false, convexity = 10, twist = -500) translate([2, 0, 0]) circle(r = 1);
Mesh Refinement
The slices parameter can be used to improve the output.
linear_extrude(height = 10, center = false, convexity = 10, twist = 360, slices = 100) translate([2, 0, 0]) circle(r = 1);
The special variables $fn, $fs and $fa can also be used to improve the output.
linear_extrude(height = 10, center = false, convexity = 10, twist = 360, $fn = 100) translate([2, 0, 0]) circle(r = 1);
Rotate Extrude
A rotational extrusion is a Linear Extrusion with a twist, literally. Unfortunately, it can not be used to produce a helix for screw threads as the 2D outline must be normal to the axis of rotation.
Examples
A simple torus can be constructed using a rotational extrude.
rotate_extrude(convexity = 10) translate([2, 0, 0]) circle(r = 1);
Mesh Refinement
Increasing the number of fragments that the 2D shape is composed of will improve the quality of the mesh, but take longer to render.
rotate_extrude(convexity = 10) translate([2, 0, 0]) circle(r = 1, $fn = 100);
The number of fragments used by the extrusion can also be increased.
rotate_extrude(convexity = 10, $fn = 100) translate([2, 0, 0]) circle(r = 1, $fn = 100);
Extruding a Polygon
Extrusion can also be performed on polygons with points chosen by the user.
Here is a simple polygon.
rotate([90,0,0]) polygon( points=[[0,0],[2,1],[1,2],[1,3],[3,4],[0,5]] );
Here is the same polygon, rotationally extruded, and with the mesh refinement set to 200. The polygon must touch the rotational axis for the extrusion to work, i.e. you can't build a polygon rotation with a hole.
rotate_extrude($fn=200) polygon( points=[[0,0],[2,1],[1,2],[1,3],[3,4],[0,5]] );
For more information on polygons, please see: 2D Primitives: Polygon.
Description of extrude parameters
Extrude parameters for all extrusion modes
| convexity | Integer. The convexity parameter specifies the maximum number of front sides (back sides) a ray intersecting the object might penetrate.
This parameter is only needed for correctly displaying the object in OpenCSG preview mode and has no effect on the polyhedron rendering. |
This image shows a 2D shape with a convexity of 4, as the ray indicated in red crosses the 2D shape a maximum of 4 times. The convexity of a 3D shape would be determined in a similar way. Setting it to 10 should work fine for most cases.
Extrude parameters for linear extrusion only
| height | The extrusion height |
| center | If true the solid will be centered after extrusion |
| twist | The extrusion twist in degrees |
| slices | Similar to special variable $fn without being passed down to the child 2D shape. |