omdl  v0.9.5
OpenSCAD Mechanical Design Library
Primitives

Drafting base functions and primitives. More...

+ Collaboration diagram for Primitives:

Files

file  primitive.scad
 Drafting base functions and primitives.
 

Layers

function draft_layers_any_active (layers=draft_get_config("layers-default"))
 Check if any identified layers are active. More...
 

Placement

function draft_sheet_get_zone (rx, ry, ix, iy, zp=0, window=false, frame=false)
 Get sheet, sheet-frame, or sheet-zone reference coordinates. More...
 

Tables

function draft_table_get_cell (ix, iy, zp=0, limits=false, window=false, map, fmap)
 Get table cell coordinates given a column and row. More...
 
module draft_table_text (ix, iy, text, size, dfmt, map, fmap)
 Add text to table cell at a given a column and row. More...
 
function draft_ztable_get_zone (i, zp=0, limits=false, window=false, map)
 Get ztable zone coordinates given a zone index. More...
 
module draft_ztable_text (i, text, size, fmt, dfmt, map)
 Add text to ztable at a given zone index. More...
 

Shapes

module draft_line_pp (i, t, w=1)
 Draft a simple line from an initial to a terminal point. More...
 
module draft_arrow (l=x_axis2d_ul, w=1, s=1)
 Draft an arrowhead at the terminal point of a line. More...
 
module draft_line (l=x_axis2d_ul, w=1, s=1, a1=0, a2=0)
 Draft a line with configurable style and optional arrowheads. More...
 
module draft_arc (r=1, c=origin2d, v1=x_axis2d_uv, v2=x_axis2d_uv, fn, cw=true, w=1, s=1, a1=0, a2=0)
 Draft an arc with configurable style and optional arrowheads. More...
 
module draft_rectangle (d=1, c=origin2d, w=1, s=1)
 Draft a rectangle with configurable style. More...
 
module draft_polygon (c, p, e, i=true, w=1, s=1)
 Draft a polygon with configurable style. More...
 

Miscellaneous

module draft_make_3d_if_configured ()
 Extrude 2D drafted constructions to 3D if configured. More...
 

Detailed Description

Drafting base functions and primitives.

Function Documentation

◆ draft_arc()

module draft_arc ( = 1,
= origin2d,
v1  = x_axis2d_uv,
v2  = x_axis2d_uv,
fn  ,
cw  = true,
= 1,
= 1,
a1  = 0,
a2  = 0 
)

Draft an arc with configurable style and optional arrowheads.

Parameters
r<decimal> The arc radius.
c<point-2d> The arc center coordinate [x, y].
v1<line-2d | decimal> The arc start angle. A 2d line, vector, or decimal angle 1.
v2<line-2d | decimal> The arc end angle. A 2d line, vector, or decimal angle 2.
fn<integer> The number of [facets] (optional).
cw<boolean> Sweep clockwise along arc from the head of vector v1 to the head of vector v2 when cw = true, and counter clockwise when cw = false.
Returns
<coords-2d> A list of coordinates points [[x, y], ...].

The arc coordinates will have radius r centered about c contained within the heads of vectors v1 and v2. The arc will start at the point coincident to v1 and will end at the point coincident to v2. When vectors v1 and v2 are parallel, the arc will be a complete circle. When fn is undefined, its value is determined by get_fn(). These coordinates will be used to draft an arc according to the following additional parameters.

Parameters
w<decimal> The line weight.
s<integer | integer-list> The line style.
a1<integer | integer-list-5> The arrowhead style at initial point.
a2<integer | integer-list-5> The arrowhead style at terminal point.

When parameter s is assigned a single integer it sets the style with its default optional values. The line style s can be one of the following:

style description
0 no line
1 solid line
2 single dash pattern

Style 2 can be customize via optional parameter as shown below:

style 2

field description data type default
1 stride <decimal> 2

Object example

draft_arc

The line segments are constructed by draft_line_pp().

Definition at line 1304 of file primitive.scad.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draft_arrow()

module draft_arrow ( = x_axis2d_ul,
= 1,
= 1 
)

Draft an arrowhead at the terminal point of a line.

Parameters
l<line> A line or vector.
w<decimal> The line segment weight.
s<integer | integer-list-5> The arrowhead style.

The style can be customize via the following optional parameter list fields.

field description data type default
0 style <integer> 0
1 fill: 0,1 or true,false <integer | boolean> 0
2 side: 0=both, 1=left, 2=right <integer> 0
3 length multiplier <decimal> 1
4 angle multiplier <decimal> 1

When parameter s is assigned a single integer it sets the style and the other fields are assigned their default values.

style description
0 no arrowhead
1 closed 3-point arrowhead
2 closed 4-point arrowhead
3 open 3-point arrowhead
4 slash / cross arrowhead
5 circle arrowhead

Object example

draft_arrow

$draft_arrow_fn sets arc fragment number for arrowhead construction. The line segments are constructed by draft_line_pp().

see: draft_config_map
arrow-line-length-min
arrow-angle-min

Definition at line 988 of file primitive.scad.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draft_layers_any_active()

function draft_layers_any_active ( layers  = draft_get_config("layers-default"))

Check if any identified layers are active.

Parameters
layers<string-list> The list of layer names.
Returns
<boolean> true if any identified layer is active as indicated by draft_layers_show.
+ Here is the caller graph for this function:

◆ draft_line()

module draft_line ( = x_axis2d_ul,
= 1,
= 1,
a1  = 0,
a2  = 0 
)

Draft a line with configurable style and optional arrowheads.

Parameters
l<line> A line or vector.
w<decimal> The line weight.
s<integer | integer-list> The line style.
a1<integer | integer-list-5> The arrowhead style at initial point.
a2<integer | integer-list-5> The arrowhead style at terminal point.

When parameter s is assigned a single integer it sets the style with its default optional values. The line style s can be one of the following:

style description
0 no line
1 solid line
2 single dash pattern centered
3 dual overlapped dash patterns
4 both ends and center
5 line section break

Each style can be customize via optional parameter list fields. The options differ by style:

style 2

field description data type default
1 length multiplier <decimal> 1
2 stride <decimal> 2

style 3

field description data type default
1 length multiplier 1 <decimal> 1
2 stride 1 <decimal> 2
3 length multiplier 2 <decimal> 2
4 stride 2 <decimal> 3

style 4

field description data type default
1 number of centered segments <decimal> 1
2 centered-length multiplier <decimal> 1
3 end-length multiplier <decimal> 1

style 5

field description data type default
1 number of breaks <decimal> 1
2 break length multiplier <decimal> 2
3 break width multiplier <decimal> 2
4 break angle <decimal> 67.5

Object example

draft_line

The line segments are constructed by draft_line_pp().

see: draft_config_map
line-segment-min

Definition at line 1162 of file primitive.scad.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draft_line_pp()

module draft_line_pp ( ,
,
= 1 
)

Draft a simple line from an initial to a terminal point.

Parameters
i<point-2d> The initial point coordinate [x, y].
t<point-2d> The terminal point coordinate [x, y].
w<decimal> The line weight.

$draft_line_fn sets arc fragment number for line construction.

see: draft_config_map
line-width-min
line-use-hull

Definition at line 917 of file primitive.scad.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draft_make_3d_if_configured()

module draft_make_3d_if_configured ( )

Extrude 2D drafted constructions to 3D if configured.

When $draft_make_3d is true, all children objects are extruded to 3D.

see: draft_config_map
make-3d-height

Definition at line 1461 of file primitive.scad.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draft_polygon()

module draft_polygon ( ,
,
,
= true,
= 1,
= 1 
)

Draft a polygon with configurable style.

Parameters
c<coords-2d> A list of 2d coordinate points.
p<integer-list-list> A list of paths that enclose the shape where each face is a list of coordinate indexes.
e<integer-list-2-list> A list of edges where each edge is a list of two coordinate indexes.
i<index> An index sequence specification.
w<decimal> The line weight.
s<integer | integer-list> The line style.

Parameter p is optional and when it is not given, the listed order of the coordinates establishes the polygon path. When parameter e is not specified, it is computed from p using polytope_faces2edges(). Parameter i allows coordinate indexes to be selected using several selection schemes.

Object example

draft_polygon

The line segments are constructed by draft_line().

Definition at line 1420 of file primitive.scad.

+ Here is the call graph for this function:

◆ draft_rectangle()

module draft_rectangle ( = 1,
= origin2d,
= 1,
= 1 
)

Draft a rectangle with configurable style.

Parameters
d<decimal-list-2 | decimal> A list [x, y] of decimals or a single decimal for (x=y).
c<point-2d> The center coordinate [x, y].
w<decimal> The line weight.
s<integer | integer-list> The line style.

Object example

draft_rectangle

The line segments are constructed by draft_line().

Definition at line 1362 of file primitive.scad.

+ Here is the call graph for this function:

◆ draft_sheet_get_zone()

function draft_sheet_get_zone ( rx  ,
ry  ,
ix  ,
iy  ,
zp  = 0,
window  = false,
frame  = false 
)

Get sheet, sheet-frame, or sheet-zone reference coordinates.

Parameters
rx<string-list | string> Sheet x-axis zone reference identifier(s).
ry<string-list | string> Sheet y-axis zone reference identifier(s).
ix<integer-list | integer> Sheet x-axis zone reference index(es).
iy<integer-list | integer> Sheet x-axis zone reference index(es).
zp<integer-list-2 | integer> The window coordinate scaler. A list [zpx, zpy] of decimals or a single decimal for (zpx=zpy).
window<boolean> Return window rather than point.
frame<boolean> Use frame when zone not specified.
Returns
<datastruct> The reference coordinates.

The returned datastruct will be one of the following forms:

window description data type
true [p0, p1, p2, p3], pn=[x,y] <point-2d-list-4>
false [x, y] <point-2d>

The parameter zp is used to linearly scale the window coordinate. For both axes, -1 = left/bottom, 0 = center/middle, and +1 = right/top. The windows coordinate points [p0, p1, p2, p3] are clockwise ordered with p0=[xmin, ymin].

+ Here is the caller graph for this function:

◆ draft_table_get_cell()

function draft_table_get_cell ( ix  ,
iy  ,
zp  = 0,
limits  = false,
window  = false,
map  ,
fmap   
)

Get table cell coordinates given a column and row.

Parameters
ix<integer> A table column vertical line index.
iy<integer> A table row horizontal line index.
zp<integer-list-2 | integer> The cell coordinate scaler. A list [zpx, zpy] of decimals or a single decimal for (zpx=zpy).
limits<boolean> Return cell limits rather than coordinates.
window<boolean> Return cell window rather than point.
map<map> A table definition map.
fmap<map> A table format map.
Returns
<datastruct> The table cell coordinates.

The returned datastruct will be one of the following forms:

limits window description data type
true - [[xmin, xmax], [ymin, ymax]] <decimal-list-2-list-2>
false true [p0, p1, p2, p3], pn=[x,y] <point-2d-list-4>
false false [x, y] <point-2d>

The parameter zp is used to linearly scale the window coordinate. For both axes, -1 = left/bottom, 0 = center/middle, and +1 = right/top. The windows coordinate points [p0, p1, p2, p3] are clockwise ordered with p0=[xmin, ymin].

+ Here is the caller graph for this function:

◆ draft_table_text()

module draft_table_text ( ix  ,
iy  ,
text  ,
size  ,
dfmt  ,
map  ,
fmap   
)

Add text to table cell at a given a column and row.

Parameters
ix<integer> A table column vertical line index.
iy<integer> A table row horizontal line index.
text<string | string-list> The text to add. A single string or a list of strings for multiple line text.
size<decimal> The text size.
dfmt<datastruct> The default text format.
map<map> A table definition map.
fmap<map> A table format map.

The parameter dfmt of type <datastruct> is a list of eleven values:

  <datastruct> =
  [
    0:text, 1:<align-point>, 2:<align-offset>, 3:<multi-line-offset>,
    4:rotate, 5:text-scale, 6:<text-align>, 7:font,
    8:spacing, 9:direction, 10:language, 11:script
  ]
field description data type
0 text <string>
1 [h-align, v-align] <decimal-list-2>
2 [h-offset, v-offset] <decimal-list-2>
3 [h-offset, v-offset] <decimal-list-2>
4 rotate <decimal>
5 text-scale <decimal>
6 [h-align, v-align] <string-list-2>
7 font <string>
8 spacing <decimal>
9 direction <string>
10 language <string>
11 script <string>

Example

dfmt = [empty_str, [-1,-1], [2/5,-9/10], [0,-1-1/5], 0, 1, ["left", "center"]]];
empty_str
<string> A string with no characters (the empty string).
Definition: constants.scad:301

Unassigned fields are initialized with defaults.

Definition at line 627 of file primitive.scad.

+ Here is the call graph for this function:

◆ draft_ztable_get_zone()

function draft_ztable_get_zone ( ,
zp  = 0,
limits  = false,
window  = false,
map   
)

Get ztable zone coordinates given a zone index.

Parameters
i<integer> A ztable zone index.
zp<integer-list-2 | integer> The zone coordinate scaler. A list [zpx, zpy] of decimals or a single decimal for (zpx=zpy).
limits<boolean> Return zone limits rather than coordinates.
window<boolean> Return zone window rather than point.
map<map> A ztable definition map.
Returns
<datastruct> The ztable cell coordinates.

The returned datastruct will be one of the following forms:

limits window description data type
true - [[xmin, xmax], [ymin, ymax]] <decimal-list-2-list-2>
false true [p0, p1, p2, p3], pn=[x,y] <point-2d-list-4>
false false [x, y] <point-2d>

The parameter zp is used to linearly scale the window coordinate. For both axes, -1 = left/bottom, 0 = center/middle, and +1 = right/top. The windows coordinate points [p0, p1, p2, p3] are clockwise ordered with p0=[xmin, ymin].

+ Here is the caller graph for this function:

◆ draft_ztable_text()

module draft_ztable_text ( ,
text  ,
size  ,
fmt  ,
dfmt  ,
map   
)

Add text to ztable at a given zone index.

Parameters
i<integer> A ztable zone index.
text<string | string-list> The text to add. A single string or a list of strings for multiple line text.
size<decimal> The text size.
fmt<datastruct> The text format.
dfmt<datastruct> The default text format.
map<map> A ztable definition map.

The parameters fmt and dfmt of type <datastruct> is a list of eleven values:

  <datastruct> =
  [
    0:text, 1:<align-point>, 2:<align-offset>, 3:<multi-line-offset>,
    4:rotate, 5:text-scale, 6:<text-align>, 7:font,
    8:spacing, 9:direction, 10:language, 11:script
  ]
field description data type
0 text <string>
1 [h-align, v-align] <decimal-list-2>
2 [h-offset, v-offset] <decimal-list-2>
3 [h-offset, v-offset] <decimal-list-2>
4 rotate <decimal>
5 text-scale <decimal>
6 [h-align, v-align] <string-list-2>
7 font <string>
8 spacing <decimal>
9 direction <string>
10 language <string>
11 script <string>

Example

dfmt = [empty_str, [-1,-1], [2/5,-9/10], [0,-1-1/5], 0, 1, ["left", "center"]]];

Unassigned fields are initialized with defaults.

Definition at line 852 of file primitive.scad.

+ Here is the call graph for this function: