## 2D Primitives

‘2D’ stands for two (2) dimensional. A 2D primitive is any shape that has two dimensions, which are width and length (or X and Y.) The 2D dimensional shapes have no thickness (Although, JSCAD shows a very thin shape.)

One way of thinking about 2D shapes is anything that lays flat on a piece of paper, such as drawing a circle or a square.

The mathematical study of 2D shapes and dimensions is called plane geometry.

#### Resolution of Shapes

All rounded shapes have a `resolution` option which controls tesselation. If `resolution` is set to 8, then 8 polygons are used to create 360 degrees of revolution.

This allows each design to control the amount of detail present, but beware that calculations and rendering time will also increase. For example, the number of polygons increases quickly with each increase of the `resolution` for circles.

EXAMPLE

If the `resolution` option is omitted, the following resolution is used.

• CSG.defaultResolution2D = 32

OpenSCAD like functions support the `fn` parameter, which is the same as `resolution`.

### Rectangle

A two dimensional shape made with four straight sides where all interior angles are right angles (90°).

The following show examples of creating rectangles. The radius specifies the size. Rectangles with different radius for X and Y axis can be specified by supplying an array of values.

Defaults:

• radius : 1 or [1,1]
• center : [0,0]
```square(5);                                  // square 5 x 5
square([2,3]);                              // rectangle 2 x 3
square({size: [2,4], center: true});        // rectangle 2 x 4, centered on both X and Y axis```

The CSG library functions can also be used. NOTE: Deprecated in the V2 API

```CAG.rectangle({center: [0,0], radius: [5, 10]});

### Circle

A two dimensional shape made by drawing a curve that is always the same distance from a center. All points are the same distance from the center.

The following show examples of creating circles. The radius specifies the size. The resolution option determines the number of segments to create in 360 degrees of rotation.

Note: See the start of 2D Primitives for information about the resolution of two dimensional shapes.

Defaults:

• center : [0,0]
• resolution: defaultResolution2D (32)
```let c1 = circle(1)
let c2 = circle({r: 2, fn:5})            // fn = number of segments to approximate the circle
let c3 = circle({r: 3, center: true})```

The CSG library functions can also be used. NOTE: Deprecated in the V2 API

`let c4 = CAG.circle({center: [0,0], radius: 3, resolution: 32})`

### Polygon

A two dimensional shape with straight sides, and the shape is “closed” (all the sides connect up).

The following show examples of creating polygons from a list of points.

Defaults:

• empty
```let p1 = polygon([ [0,0],[3,0],[3,3] ])
let p2 = polygon({ points: [ [0,0],[3,0],[3,3] ] })```

The CSG library functions can also be used. NOTE: Deprecated in the V2 API

`let p3 = CAG.fromPoints([ [0,0],[5,0],[3,5],[0,5] ])`