# Objects
## Primitives
### Primitive Solids

OpenSCAD provides four 3D primitive solids: cube, sphere, cylinder, and polyhedron. Note that surface and import may also be considered as primitive solids.

### Primitive Shapes

OpenSCAD provides four 2D primitive shapes: square, circle, polygon, and text.

## Flow Control
### if ... else ...

| Conditional Object | if (expr_Q) object_T; |
| Conditional Object | if (expr_Q) object_T; else object_F; |
The conditional object performs a test (evaluates the query expr_Q), and renders either object_T or object_F depending on the truth value of the test result. If object_F was to be nothing, then the else object_F; portion is optional.
More commonly, the compound statement form of if is used, as exemplified by:
If the result of the conditional evaluation is not an object, but a quantity, use the ? : conditional operator.
While it is allowed to assign variables in the compound form, the scope of those variables is limited to the curly brackets.
The outcome is a small and a large sphere, and in the console:
Note that "a is 10" within the scope of the curly bracket, the corresponding statement a = 10; need not precede the echo and sphere statements for its effect to apply. After the if statement, the assignment to a is lost, so we "recall" a is still 5.
See Scope of variables for more details.
    Nested if
Since a complete if statement is an object, it can be nested in another if statement.
A common form is multiply nested "else if" statements:

### intersection_for ...
## Imported Objects

import
surface

## Null Object

echo

# Operators
## Arithmetic Operators

The scalar arithmetical operators take numbers as operands and produce a new number.
| + | add |
| - | subtract |
| - | negate (unary) |
| * | multiply |
| / | divide |
| % | modulo |

## Conditional Operator ? :

| Conditional Operator | expr_Q ? expr_T : expr_F |
An operator which returns either of two expressions depending on the truth value of a query expression. For example:
var = expr_Q ? expr_T : expr_F;
The expression expr_Q is evaluated and if it's true, expr_T is evaluated and assigned to var; otherwise expr_F is evaluated and assigned to var. If expr_Q evaluated to a non-Boolean result, it is converted to Boolean; see here.
The conditional operator is essential when creating a recursive function call, because it is used to terminate the recursion; see here.
The conditional operator can be used like a nested if also, as in the following example:
NSides = (FF=="triangular") ? 3 : (FF=="hexagonal") ? 6 (FF=="octagonal") ? 8 : (FF=="circular") ? 180 : 0;

# Functions
## Math Functions
### Trigonometric Functions

The trigonometric functions use the C Language mathematics library functions. Remember all numbers in OpenSCAD are IEEE double floating points. A good reference for the specifics of the C math library are (math.h) and (acos) at the Open Group website. For a quick reference to the relevant mathematics, see Trigonometric functions.
Note that the trigonometric functions do not work on vectors. Invalid inputs produce nan (e.g. acos(2)) or undef (e.g. sin("2")).
| Function | Description | Notes |
| sin(x) | trigonometric sine of x | -inf < x < inf is in degrees, return value in [-1,+1] |
| cos(x) | trigonometric cosine of x | -inf < x < inf is in degrees, return value in [-1,+1] |
| tan(x) | trigonometric tangent of x | -inf < x < inf is in degrees, return value in (-inf, inf) |
| asin(x) | inverse sine of x | -1 <= x <= 1, return value in [-90,+90] (degrees) |
| acos(x) | inverse cosine of x | -1 <= x <= 1, return value in [0,+180] (degrees) |
| atan(x) | inverse tangent of x | -inf <= x <= inf, return value in [-90,+90] (degrees) |
| atan2(y, x) | inverse tangent of y/x | -inf <= x,y <= inf, return value in [-180,+180] (degrees) see also: atan2 More precisely the return value is the angle between the line joining origin to the point (x,y) and the X-axis |

### Real Functions

Real functions require numeric inputs and produce numbers, except for rands which returns a vector of numbers.
| Function | Description | Notes |
| abs(x) | absolute value of x | -inf < x < inf, return value in [0,+inf) |
| sign(x) | sign of x, see also Sign function | -inf < x < inf, return value is 1, 0, or -1, if x is greater than, equal to, or less than 0 |
| ceil(x) | ceiling (integer) of real number x, see also: Ceil Function | -inf < x < inf, return value is the smallest integer not less than x also known as rounding off a number towards +inf |
| floor(x) | floor (integer) of real number x, see also: Floor Function | -inf < x < inf, return value is the largest integer not greater than x also known as rounding off a number towards -inf |
| round(x) | rounding function of real number x | -inf < x < inf, return value is the integer nearest to x |
| pow(x,y) | x raised to the power of y, i.e. $x^{y}$ | -inf < x,y < inf |
| sqrt(x) | square root of x, i.e. ${\sqrt {x}}$ | 0 <= x < inf, return value is the integer nearest to x, if x is negative, returns nan |
| exp(x) | exponential function of x, i.e. $e^{x}$, see also: Exponent | -inf < x < inf |
| ln(x) | natural logarithm of x, i.e. $\ln x=\log _{e}x$, see also: Natural logarithm | 0 <= x < inf, if x is negative, returns nan |
| log(x) | logarithm (base 10) of x, i.e. $\log x=\log _{10}x$, see also: Logarithm | 0 <= x < inf, if x is negative, returns nan |
| rands(a,b,n) | pseudo random number generator, see the main article | return a vector with n random numbers in the range [a, b] |
Some examples:

### Pseudo Random number generator

Generates a vector of pseudo random numbers. In order to generate a single random value as a number, instead of a vector of length 1, use x = rands(a,b,1)[0];. A seed value can be supplied optionally. From the moment a seed value is given, the sequence of pseudo random numbers being generated is deterministic. This provide a convenient way to debug the program using a constant seed value between repeated execution of the program.
Parameters

#### min_value

    Minimum value of random number range

#### max_value

    Maximum value of random number range

#### value_count

    Number of random numbers to return as a vector

#### seed_value (optional)

    Seed value for random number generator for repeatable results. On versions before late 2015, seed_value gets rounded to the nearest integer
Usage Examples:

## Vector Functions

cross, norm
max, min
len, concat
lookup
search

## String Functions

str, chr
search

## Importing Functions

dxf_cross
dxf_dim

## Debugging Functions

parent_module(n)

# Functions and Module Definitions
## Function Definition

function name(param_list) = expr;
Note that inside a function definition, variables defined in the main scope is accessible. See variables and scopes.

### Recursive function calls

Recursive function calls are supported. Using the Conditional Operator it's possible to ensure the recursion is terminated. Note: There is a built-in recursion limit to prevent an application crash. If the limit is hit, the function returns undef.
    example

## Module Definition
### children
# Pre-processor Commands

include <>
use <>

## Note on Library management
# Special Variables

$t
$fn etc
$vpn etc
$parent_modules

# Modifiers

A modifier, when preceding an object, modifies the behavior of the interpreter during preview and rendering for that object or all other objects in the program. They are essential aids to the user when designing even a minimally complicated object.