Jump to content

User:LABoyd2/Vector from manual 150927

From Wikibooks, open books for an open world

Vectors

[edit | edit source]

A vector is a sequence of zero or more OpenSCAD values. Vectors are most commonly used to represent points in 3-space (as [x,y,z] triples), to represent lists of points, and to represent the size of a cuboid (also as an [x,y,z] triple).

A vector is written as a list of zero or more expressions, separated by commas, and enclosed in square brackets, Eg, [] or [10,20,30].

Example

deck = [64, 89, 18];
cube(deck);

Output A cube with the sizes: X = 64, Y = 89, Z = 18.

Vectors selection
[edit | edit source]

You can also refer to individual values in a vector with vector[number]. number starts from 0.

Example

deck = [64, 89, 18];
translate([0,0,deck[2]]) cube(deck);

Output The same cube as the previous example would be raised by 18 on the Z axis, since vector indices are numbered [0,1,2] for [X,Y,Z] respectively.

Matrix
[edit | edit source]

A matrix is a vector of vectors.

Example

mr = [
      [cos(angle), -sin(angle)],
      [sin(angle),  cos(angle)]
     ];

Output Define a 2D rotation matrix.