# OpenSCAD User Manual/2D Primitives

All 2D primitives can be transformed with 3D transformations. They are usually used as part of a 3D extrusion. Although they are infinitely thin, they are rendered with a 1-unit thickness.
Note: Trying to subtract with difference from 3D object will lead to unexpected results in final rendering.

### square

Creates a square or rectangle in the first quadrant. When center is true the square is centered on the origin. Argument names are optional if given in the order shown here.
    parameters:
       size
          single value, square with both sides this length
          2 value array [x,y], rectangle with dimensions x and y
       center
          false (default), 1st (positive) quadrant, one corner at (0,0)
          true, square is centered at (0,0)
    examples:

### circle

Creates a circle at the origin. All parameters, except r, must be named.
    Parameters
       r : circle radius. r name is the only one optional with circle.
          circle resolution is based on size, using $fa or $fs.
          For a small, high resolution circle you can make a large circle, then scale it down, or you could set $fn or other special variables. Note: These examples exceed the resolution of a 3d printer as well as of the display screen.
       d : circle diameter (only available in versions later than 2014.03).
       $fa : minimum angle (in degrees) of each fragment.
       $fs : minimum circumferential length of each fragment.
       $fn : fixed number of fragments in 360 degrees. Values of 3 or more override $fa and $fs.
          If they are used, $fa, $fs and $fn must be named parameters. click here for more details,.
Equivalent scripts for this example

#### Ellipses

An ellipse can be created from a circle by using either scale or resize to make the x and y dimensions unequal. See OpenSCAD User Manual/Transformations

#### Regular Polygons

A regular polygon of 3 or more sides can be created by using circle with $fn set to the number of sides. The following two pieces of code are equivalent.
These result in the following shapes, where the polygon is inscribed within the circle with all sides (and angles) equal. One corner points to the positive x direction. For irregular shapes see the polygon primitive below.

### polygon

The function polygon creates a multiple sided shape from a list of x,y coordinates. A polygon is the most powerful 2D object. It can create anything that circle and squares can, as well as much more. This includes irregular shapes with both concave and convex edges. In addition it can place holes within that shape.

#### Parameters

    points
       The list of x,y points of the polygon. : A vector of 2 element vectors.
       Note: points are indexed from 0 to n-1.
    paths
       default
          If no path is specified, all points are used in the order listed.
       single vector
          The order to traverse the points. Uses indices from 0 to n-1. May be in a different order and use all or part, of the points listed.
       multiple vectors
          Creates primary and secondary shapes. Secondary shapes are subtracted from the primary shape (like difference). Secondary shapes may be wholly or partially within the primary shape.
       A closed shape is created by returning from the last point specified to the first.
    convexity
       Integer number of "inward" curves, ie. expected path crossings of an arbitrary line through the polygon. See below.

#### One hole

The 1st path vector, [0,1,2], selects the points, [0,0],[100,0],[0,100], for the primary shape. The 2nd path vector, [3,4,5], selects the points, [10,10],[80,10],[10,80], for the secondary shape. The secondary shape is subtracted from the primary ( think difference ). Since the secondary is wholly within the primary, it leaves a shape with a hole.

#### Multi hole

[Note: Requires version 2015.03] (for use of concat)

#### convexity

The convexity parameter specifies the maximum number of front sides (back sides) a ray intersecting the object might penetrate. This parameter is needed only for correct display of the object in OpenCSG preview mode and has no effect on the polyhedron rendering.
This image shows a 2D shape with a convexity of 2, as the ray indicated in red crosses the 2D shapes outside⇒inside (or inside⇒outside) a maximum of 2 times. The convexity of a 3D shape would be determined in a similar way. Setting it to 10 should work fine for most cases.

### import_dxf

[Deprecated: import_dxf will be removed in future releases. Use import instead.]
Read a DXF file and create a 2D shape.
Example