omdl  v0.6.1
OpenSCAD Mechanical Design Library
Resolutions

Arch rendering resolution management. More...

+ Collaboration diagram for Resolutions:

Files

file  units_resolution.scad
 An abstraction for arc rendering resolution control.
 

Functions

function resolution_fn (r)
 Return facets number for the given arc radius. More...
 
function resolution_fs ()
 Return minimum facets size. More...
 
function resolution_fa (r)
 Return the minimum facets angle. More...
 
function resolution_reduced ()
 Return the radius at which arc resolution will begin to degrade. More...
 
module resolution_info (r)
 Output resolution information to the console for given radius. More...
 
function resolution_facets (r)
 Return facet count used to render a radius. More...
 
function resolution_facetsv (r)
 Return facet count information list used to render a radius. More...
 

Variables

 $resolution_mode = "fast"
 <string> Global special variable that configures the arc resolution mode.
 
 $resolution_value = 0
 <number> Global special variable for modes that use custom resolutions.
 

Detailed Description

Arch rendering resolution management.

Functions, global variables, and configuration presets to provide a common mechanism for managing arc rendering resolution. Specifically, the number of fragments/facets with which arcs (circles, spheres, and cylinders, etc.) are rendered in OpenSCAD.

Example

include <units/units_resolution.scad>;
// set resolution to 25 fpi
// use radius length of 1 inch
r = convert_length(1, "in");
$fa=resolution_fa( r );
echo(str("for r = ", r, " ", unit_length_name(), ", facets = ", f));

Result (base_unit_length = mm):

ECHO: "$resolution_mode = [fpi], $resolution_value = 25, base_unit_length = millimeter"
ECHO: "$fn = 0, $fa = 2.29183, $fs = 1.016"
ECHO: "resolution reduction at radius > 25.4 millimeter"
ECHO: "for radius = 25.4 millimeter facets limited to 158 by $fs=1.016 millimeter"
ECHO: "for r = 25.4 millimeter, facets = 158"

Result (base_unit_length = cm):

ECHO: "$resolution_mode = [fpi], $resolution_value = 25, base_unit_length = centimeter"
ECHO: "$fn = 0, $fa = 2.29183, $fs = 0.1016"
ECHO: "resolution reduction at radius > 2.54 centimeter"
ECHO: "for radius = 2.54 centimeter facets limited to 158 by $fs=0.1016 centimeter"
ECHO: "for r = 2.54 centimeter, facets = 158"

Result (base_unit_length = mil):

ECHO: "$resolution_mode = [fpi], $resolution_value = 25, base_unit_length = thousandth"
ECHO: "$fn = 0, $fa = 2.29183, $fs = 40"
ECHO: "resolution reduction at radius > 1000 thousandth"
ECHO: "for radius = 1000 thousandth facets limited to 158 by $fs=40 thousandth"
ECHO: "for r = 1000 thousandth, facets = 158"

Result (base_unit_length = in):

ECHO: "$resolution_mode = [fpi], $resolution_value = 25, base_unit_length = inch"
ECHO: "$fn = 0, $fa = 2.29183, $fs = 0.04"
ECHO: "resolution reduction at radius > 1 inch"
ECHO: "for radius = 1 inch facets limited to 158 by $fs=0.04 inch"
ECHO: "for r = 1 inch, facets = 158"

Function Documentation

function resolution_fa ( )

Return the minimum facets angle.

Parameters
r<decimal> The arc radius.
Returns
<decimal> Minimum facet angle to be assigned to $fa.

The result of this function can be assigned to the special variables $fa to render arcs.

function resolution_facets ( )

Return facet count used to render a radius.

Parameters
r<decimal> The arc radius.
Returns
<integer> The number of fragments/facets that will be used to render a radius given the current values for $fn, $fa, and $fs.
function resolution_facetsv ( )

Return facet count information list used to render a radius.

Parameters
r<decimal> The arc radius.
Returns
<list-3> A 3-tuple list of the form: [facets <integer>,limiter <string>,value <decimal>].

Where facets is the number of fragments/facets that will be used to render the radius given the current values for $fn, $fa, and $fs. limiter identifies the special variable that currently limits the facets, and value is the current value assigned to the limiter.

function resolution_fn ( )

Return facets number for the given arc radius.

Parameters
r<decimal> The arc radius.
Returns
<integer> The number of facets to be assigned to $fn.

The result of this function can be assigned to the special variables $fn to render arcs according to the resolution mode set by $resolution_mode and $resolution_value.

The following table shows the modes that require $resolution_value to be set prior to specifying the custom values used during resolution calculation.

$resolution_mode $resolution_value sets radius dependent
set fixed value no
upf units per facet yes
fpu facets per unit yes
fpi facets per inch yes

The following table has common resolution presets. Equivalent configuration can be obtained using $resolution_mode and $resolution_value as described in the preview table.

$resolution_mode preset description radius dependent
fast fast rendering mode no
low low resolution yes
medium medium resolution yes
high high resolution yes
50um 50 micron per facets yes
100um 100 micron per facets yes
200um 200 micron per facets yes
300um 300 micron per facets yes
400um 400 micron per facets yes
500um 500 micron per facets yes
50mil 50 thousandth per facets yes
100mil 100 thousandth per facets yes
200mil 200 thousandth per facets yes
300mil 300 thousandth per facets yes
400mil 400 thousandth per facets yes
500mil 500 thousandth per facets yes
function resolution_fs ( )

Return minimum facets size.

Returns
<integer> Minimum facet size to be assigned to $fs.

The result of this function can be assigned to the special variables $fs to render arcs according to the resolution mode set by $resolution_mode and $resolution_value.

The following table shows the modes that require $resolution_value to be set prior to calling this function in order to specify the custom values used during resolution calculation.

$resolution_mode $resolution_value sets radius dependent
set fixed value no
upf units per facet no
fpu facets per unit no
fpi facets per inch no

The following table has common resolution presets. Equivalent configuration can be obtained using $resolution_mode and $resolution_value as described in the preview table.

$resolution_mode preset description radius dependent
fast fast rendering mode no
low low resolution no
medium medium resolution no
high high resolution no
50um 50 micron per facets no
100um 100 micron per facets no
200um 200 micron per facets no
300um 300 micron per facets no
400um 400 micron per facets no
500um 500 micron per facets no
50mil 50 thousandth per facets no
100mil 100 thousandth per facets no
200mil 200 thousandth per facets no
300mil 300 thousandth per facets no
400mil 400 thousandth per facets no
500mil 500 thousandth per facets no
module resolution_info ( )

Output resolution information to the console for given radius.

Parameters
r<decimal> The arc radius.

Definition at line 322 of file units_resolution.scad.

+ Here is the call graph for this function:

function resolution_reduced ( )

Return the radius at which arc resolution will begin to degrade.

Returns
<decimal> Transition radius where resolution reduction begins.

The special variables $fs and $fa work together when $fn = 0. For a given $fs, the fragment angle of a drawn arc gets smaller with increasing radius. In other words, the fragment angle is inversely proportional to the arc radius for a given fragment size.

The special variable $fa enforces a minimum fragment angle limit and at some radius, the fragment angle would becomes smaller than this limit. At this point, OpenSCAD limits further reduction in the facet angle which forces the use of increased fragment size. This in effect begins the gradual reduction of arc resolution with increasing radius.

The return result of this function indicates the radius at which this enforced limiting begins. When $fn != 0, returns undef.

+ Here is the caller graph for this function: