omdl
v0.6.1
OpenSCAD Mechanical Design Library
|
Coordinate systems and conversions. More...
Files | |
file | units_coordinate.scad |
Coordinate systems and conversions. | |
Functions | |
function | coordinates_name (s=base_coordinates) |
Return the name of the given coordinate system identifier. More... | |
function | convert_coordinate (c, from=base_coordinates, to=base_coordinates) |
Convert point from one coordinate system to another. More... | |
function | coordinates_cpc (c, r, t=false) |
Radially scale a list of 2d cartesian coordinates. More... | |
function | coordinates_pc (p, r, t=false) |
Radially scale and convert a list of 2d polar coordinates to cartesian. More... | |
function | coordinates_csc (c, r, t=false) |
Radially scale a list of 3d cartesian coordinates. More... | |
function | coordinates_sc (s, r, t=false) |
Radially scale and convert a list of 3d spherical coordinates to cartesian. More... | |
Variables | |
base_coordinates = "c" | |
<string> The base coordinate system. | |
coordinates_positive_angles = true | |
<boolean> When converting to angular measures add 360 to negative angles. | |
Coordinate systems and conversions.
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 |
Example
Result (base_coordinates = c):
Result (base_coordinates = p):
Result (base_coordinates = y):
Result (base_coordinates = s):
function convert_coordinate | ( | c | , |
from | = base_coordinates , |
||
to | = base_coordinates |
||
) |
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 coordinates_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 coordinates_csc | ( | c | , |
r | , | ||
t | = false |
||
) |
Radially 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 coordinates_name | ( | s | = base_coordinates | ) |
Return the name of the given coordinate system identifier.
s | <string> A coordinate system identifier. |
function coordinates_pc | ( | 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 coordinates_sc | ( | s | , |
r | , | ||
t | = false |
||
) |
Radially 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
.