# OpenSCAD User Manual/2D to 3D Extrusion

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 ExtrudeEdit

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.

#### UsageEdit

```linear_extrude(height = fanwidth, center = true, convexity = 10, twist = -fanrot, slices = 20, scale = 1.0) {...}
```

You must use parameter names due to a backward compatibility issue.

If the extrusion fails for a non-trival 2D shape, try setting the convexity parameter (the default is not 10, but 10 is a "good" value to try). See explanation further down.

#### TwistEdit

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);
```

#### CenterEdit

Center determines if the object is centered on the Z-axis 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 RefinementEdit

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);
```

#### ScaleEdit

Scales the 2D shape by this value over the height of the extrusion. Scale can be a scalar or a vector:

``` linear_extrude(height = 10, center = true, convexity = 10, scale=3)
translate([2, 0, 0])
circle(r = 1);
```

``` linear_extrude(height = 10, center = true, convexity = 10, scale=[1,5], \$fn=100)
translate([2, 0, 0])
circle(r = 1);
```

Note that if scale is a vector, the resulting side walls may be nonplanar. Use `twist=0` and the `slices` parameter to avoid asymmetry.

``` linear_extrude(height=10, scale=[1,0], slices=20, twist=0)
polygon(points=[[0,0],[20,10],[20,-10]]);
```

### Rotate ExtrudeEdit

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, ie they need to be flat in 2D space.

The 2D shape needs to be either completely on the positive, or negative side (not recommended), of the X axis. It can touch the axis, i.e. zero, however if the shape crosses the X axis a warning will be shown in the console windows and the rotate_extrude() will be ignored. If the shape is in the negative axis the faces will be inside-out, you probably don't want to do that; it may be fixed in the future.

#### ExamplesEdit

A simple torus can be constructed using a rotational extrude.

```rotate_extrude(convexity = 10)
translate([2, 0, 0])
circle(r = 1);
```

#### Mesh RefinementEdit

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 PolygonEdit

Extrusion can also be performed on polygons with points chosen by the user.

Here is a simple polygon and its (fine-grained: `\$fn=200`) rotational extrusion (profile and lathe). (Note it has been rotated 90 degrees to show how the rotation will look, the `rotate_extrude()` needs it flat).

```rotate([90,0,0])        polygon( points=[[0,0],[2,1],[1,2],[1,3],[3,4],[0,5]] );
// --------------------------------------------------------------------------- ;
rotate_extrude(\$fn=200) polygon( points=[[0,0],[2,1],[1,2],[1,3],[3,4],[0,5]] );
```