omdl  v0.9.5
OpenSCAD Mechanical Design Library
Coordinates Systems

Coordinate systems and conversions. More...

+ Collaboration diagram for Coordinates Systems:

Files

file  coordinate.scad
 Coordinate systems and conversions.
 

Functions

function coordinate_unit_name (s=coordinate_unit_default)
 Return the name of the given coordinate system identifier. More...
 
function coordinate (c, from=coordinate_unit_default, to=coordinate_unit_base)
 Convert point from one coordinate system to another. More...
 
function coordinate_inv (c, from=coordinate_unit_base, to=coordinate_unit_default)
 Convert point from one coordinate system to another. More...
 
function coordinate_scale2d_cpc (c, r, t=false)
 Radially scale a list of 2d cartesian coordinates. More...
 
function coordinate_scale2d_p2c (p, r, t=false)
 Radially scale and convert a list of 2d polar coordinates to cartesian. More...
 
function coordinate_scale3d_csc (c, r, t=false)
 Spherically scale a list of 3d cartesian coordinates. More...
 
function coordinate_scale3d_s2c (s, r, t=false)
 Spherically scale and convert a list of 3d spherical coordinates to cartesian. More...
 

Variables

 coordinate_unit_base = "c"
 <string> The base units for value storage.
 
 coordinate_unit_default = "c"
 <string> The default units when unspecified.
 
 coordinate_positive_angle = true
 <boolean> When converting to angular measures add 360 to negative angles.
 

Detailed Description

Coordinate systems and conversions.

Requires:
include <omdl-base.scad>;
include <units/coordinate.scad>;

These functions allow for geometric points in space to be specified using multiple coordinate systems. Some geometric calculations are specified more naturally in one or another coordinate system. These conversion functions allow for the movement between the most convenient for a particular application.

For more information see Wikipedia on coordinate system.

The table below enumerates the supported coordinate systems.

system id description dimensions point convention
c cartesian 2d or 3d [x, y] or [x, y, z]
p polar 2d [r, aa]
y cylindrical 3d [r, aa, z]
s spherical 3d [r, aa, pa]

The symbols used in the convention column are as follows:

symbol description units reference
x, y, z coordinate distance any xyz-axis
r radial distance any z-axis / xyz-origin
aa azimuthal angle degrees positive x-axis
pa polar / zenith angle degrees positive z-axis
Note
The azimuthal angle is a measure of the radial vector orthogonal projection onto the xy-plane measured from the positive x-axis. The polar angle is measured from the z-axis (zenith) to the radial vector.

Coordinate system base example script

include <omdl-base.scad>;
include <units/coordinate.scad>;
// get unit names
// absolute coordinates in a specified coordinate system.
c1 = coordinate([1, 1, 1], "c");
c2 = coordinate([1, 180]);
c3 = coordinate([1, 90, -1], "y");
c4 = coordinate([1, 5, 50], "s");
// convert between system.
c5 = coordinate([10*sqrt(2), 45, 45], from="s", to="y");
c6 = coordinate([sqrt(2), 45], to="c");
// end_include
coordinate_unit_base
<string> The base units for value storage.
function coordinate(c, from=coordinate_unit_default, to=coordinate_unit_base)
Convert point from one coordinate system to another.
function coordinate_unit_name(s=coordinate_unit_default)
Return the name of the given coordinate system identifier.
coordinate_unit_default
<string> The default units when unspecified.

coordinate_unit_base=c script output

ECHO: bu = "cartesian"
ECHO: du = "polar"
ECHO:
ECHO: c1 = [1, 1, 1]
ECHO: c2 = [-1, 0]
ECHO: c3 = [0, 1, -1]
ECHO: c4 = [0.763129, 0.0667652, 0.642788]
ECHO: c5 = [10, 45, 10]
ECHO: c6 = [1, 1]

coordinate_unit_base=p script output

ECHO: bu = "polar"
ECHO: du = "polar"
ECHO:
ECHO: c1 = undef
ECHO: c2 = [1, 180]
ECHO: c3 = undef
ECHO: c4 = undef
ECHO: c5 = [10, 45, 10]
ECHO: c6 = [1, 1]

coordinate_unit_base=y script output

ECHO: bu = "cylindrical"
ECHO: du = "polar"
ECHO:
ECHO: c1 = [1.41421, 45, 1]
ECHO: c2 = undef
ECHO: c3 = [1, 90, -1]
ECHO: c4 = [0.766044, 5, 0.642788]
ECHO: c5 = [10, 45, 10]
ECHO: c6 = [1, 1]

coordinate_unit_base=s script output

ECHO: bu = "spherical"
ECHO: du = "polar"
ECHO:
ECHO: c1 = [1.73205, 45, 54.7356]
ECHO: c2 = undef
ECHO: c3 = [1.41421, 90, 135]
ECHO: c4 = [1, 5, 50]
ECHO: c5 = [10, 45, 10]
ECHO: c6 = [1, 1]

Function Documentation

◆ coordinate()

function coordinate ( ,
from  = coordinate_unit_default,
to  = coordinate_unit_base 
)

Convert point from one coordinate system to another.

Parameters
c<point> A point to convert.
from<string> The coordinate system identifier of the point to be converted.
to<string> The coordinate system identifier to which the point should be converted.
Returns
<point> The converted result. Returns undef for identifiers that are not defined.

◆ coordinate_inv()

function coordinate_inv ( ,
from  = coordinate_unit_base,
to  = coordinate_unit_default 
)

Convert point from one coordinate system to another.

Parameters
c<point> A point to convert.
from<string> The coordinate system identifier of the point to be converted.
to<string> The coordinate system identifier to which the point should be converted.
Returns
<point> The converted result. Returns undef for identifiers that are not defined.

◆ coordinate_scale2d_cpc()

function coordinate_scale2d_cpc ( ,
,
= false 
)

Radially scale a list of 2d cartesian coordinates.

Parameters
c<coords-2d> A list of cartesian coordinates [[x, y], ...].
r<decimal> A polar radius.
t<boolean> Translate or scale radius.
Returns
<coords-2d> A list of scaled cartesian coordinates.

When t is true, all coordinates will terminate on a circle of radius r. When t is false, the radius of each coordinate is scaled by r.

◆ coordinate_scale2d_p2c()

function coordinate_scale2d_p2c ( ,
,
= false 
)

Radially scale and convert a list of 2d polar coordinates to cartesian.

Parameters
c<coords-2d> A list of polar coordinates [[r, aa], ...].
r<decimal> A polar radius.
t<boolean> Translate or scale radius.
Returns
<coords-2d> A list of scaled cartesian coordinates.

When t is true, all coordinates will terminate on a circle of radius r. When t is false, the radius of each coordinate is scaled by r.

◆ coordinate_scale3d_csc()

function coordinate_scale3d_csc ( ,
,
= false 
)

Spherically scale a list of 3d cartesian coordinates.

Parameters
c<coords-3d> A list of cartesian coordinates [[x, y, z], ...].
r<decimal> A spherical radius.
t<boolean> Translate or scale radius.
Returns
<coords-3d> A list of scaled cartesian coordinates.

When t is true, all coordinates will terminate on a sphere of radius r. When t is false, the radius of each coordinate is scaled by r.

◆ coordinate_scale3d_s2c()

function coordinate_scale3d_s2c ( ,
,
= false 
)

Spherically scale and convert a list of 3d spherical coordinates to cartesian.

Parameters
c<coords-3d> A list of spherical coordinates [[r, aa, pa], ...].
r<decimal> A spherical radius.
t<boolean> Translate or scale radius.
Returns
<coords-3d> A list of scaled cartesian coordinates.

When t is true, all coordinates will terminate on a sphere of radius r. When t is false, the radius of each coordinate is scaled by r.

◆ coordinate_unit_name()

function coordinate_unit_name ( = coordinate_unit_default)

Return the name of the given coordinate system identifier.

Parameters
s<string> A coordinate system identifier.
Returns
<string> The system name for the given identifier. Returns undef for identifiers that are not defined.