omdl
v0.9.5
OpenSCAD Mechanical Design Library
|
Coordinate systems and conversions. More...
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. | |
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 |
Coordinate system base example script
coordinate_unit_base=c script output
coordinate_unit_base=p script output
coordinate_unit_base=y script output
coordinate_unit_base=s script output
function coordinate | ( | c | , |
from | = coordinate_unit_default , |
||
to | = coordinate_unit_base |
||
) |
Convert point from one coordinate system to another.
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. |
function coordinate_inv | ( | c | , |
from | = coordinate_unit_base , |
||
to | = coordinate_unit_default |
||
) |
Convert point from one coordinate system to another.
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. |
function coordinate_scale2d_cpc | ( | c | , |
r | , | ||
t | = false |
||
) |
Radially scale a list of 2d cartesian coordinates.
c | <coords-2d> A list of cartesian coordinates [[x, y], ...]. |
r | <decimal> A polar radius. |
t | <boolean> Translate or scale radius. |
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
.
function coordinate_scale2d_p2c | ( | p | , |
r | , | ||
t | = false |
||
) |
Radially scale and convert a list of 2d polar coordinates to cartesian.
c | <coords-2d> A list of polar coordinates [[r, aa], ...]. |
r | <decimal> A polar radius. |
t | <boolean> Translate or scale radius. |
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
.
function coordinate_scale3d_csc | ( | c | , |
r | , | ||
t | = false |
||
) |
Spherically scale a list of 3d cartesian coordinates.
c | <coords-3d> A list of cartesian coordinates [[x, y, z], ...]. |
r | <decimal> A spherical radius. |
t | <boolean> Translate or scale radius. |
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
.
function coordinate_scale3d_s2c | ( | s | , |
r | , | ||
t | = false |
||
) |
Spherically scale and convert a list of 3d spherical coordinates to cartesian.
c | <coords-3d> A list of spherical coordinates [[r, aa, pa], ...]. |
r | <decimal> A spherical radius. |
t | <boolean> Translate or scale radius. |
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
.
function coordinate_unit_name | ( | s | = coordinate_unit_default | ) |
Return the name of the given coordinate system identifier.
s | <string> A coordinate system identifier. |