![]() |
omdl
v1.0
OpenSCAD Mechanical Design Library
|
Coordinate systems and conversions. More...
Collaboration diagram for Coordinates Systems:Files | |
| file | coordinate.scad |
| Coordinate systems and conversions. | |
Functions and/or Modules | |
| 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 a point from one coordinate system to another. More... | |
| function | coordinate_inv (c, from=coordinate_unit_base, to=coordinate_unit_default) |
| Convert a point from one coordinate system to another (direction-swapped defaults). More... | |
| function | coordinate_scale2d_cpc (c, r, t=false) |
| Radially scale a list of 2d cartesian coordinates. More... | |
| function | coordinate_scale2d_p2c (c, 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 (c, r, t=false) |
| Spherically scale and convert a list of 3d spherical coordinates to cartesian. More... | |
Variables | |
| coordinate_unit_base = "c" | |
| coordinate_unit_default = "c" | |
| coordinate_positive_angle = true | |
Coordinate systems and conversions.
| file | group | script | results | no test | skipped | passed | failed | warning |
|---|---|---|---|---|---|---|---|---|
| units/coordinate.scad | Coordinates Systems | Script | Results | 7 | 0 | 0 | 0 | 0 |
See complete validation results.
| Requires: |
|---|
| include <omdl-base.scad>; |
| include <units/coordinate.scad>; |
Parameter naming
c is the coordinate point (or list of coordinate points for the scale utility functions) to convert. It has no default and must always be supplied by the caller. Its required dimensionality depends on the target or source system (see Dimension requirements below).from identifies the source coordinate system; defaults to coordinate_unit_default.to identifies the target coordinate system; defaults to coordinate_unit_base.s is the coordinate system identifier string used in coordinate_unit_name. It is distinct from c (a numeric point) in both type and role; defaults to coordinate_unit_default.r is a radial scale factor used in the scale utility functions.t is a boolean flag in the scale utility functions: true translates all points to exactly radius r; false scales each point's existing radius by r.Return values
Dimension requirements
"c" (cartesian) accepts both 2d [x,y] and 3d [x,y,z]."p" (polar) requires a 2d point [r,aa]; a 3d input returns undef."y" (cylindrical) and "s" (spherical) require a 3d point; a 2d input returns undef.Angular convention
aa, pa) are in degrees.aa is measured from the positive x-axis in the xy-plane. When coordinate_positive_angle is true, negative azimuthal results are shifted by +360° so that aa is always in [0°, 360°). This applies to polar, cylindrical, and spherical output.pa (spherical only) is always in [0°, 180°] and is not affected by coordinate_positive_angle.[0,0,0], the polar angle pa is defined as 0° by convention.Global configuration
to is omitted. Defaults to "c". Intended to be overridden at the top of a design file or child scope before any coordinate function is called.from or s is omitted. Defaults to "c".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_unit_name | ( | s | = coordinate_unit_default | ) |
Return the name of the given coordinate system identifier.
| s | <string> A coordinate system identifier. |
| function coordinate | ( | c | , |
| from | = coordinate_unit_default, |
||
| to | = coordinate_unit_base |
||
| ) |
Convert a point from one coordinate system to another.
| c | <point> A point to convert. Dimensionality must satisfy the requirements of both from and to. |
| from | <string> The coordinate system identifier of the point to be converted. Defaults to coordinate_unit_default. |
| to | <string> The coordinate system identifier to which the point should be converted. Defaults to coordinate_unit_base. |
"p" requires 2d input; "y" and "s" require 3d input; "c" accepts both. See conventions for full details. | function coordinate_inv | ( | c | , |
| from | = coordinate_unit_base, |
||
| to | = coordinate_unit_default |
||
| ) |
Convert a point from one coordinate system to another (direction-swapped defaults).
| c | <point> A point to convert. Dimensionality must satisfy the requirements of both from and to. |
| from | <string> The coordinate system identifier of the point to be converted. Defaults to coordinate_unit_base. |
| to | <string> The coordinate system identifier to which the point should be converted. Defaults to coordinate_unit_default. |
from and to defaults swapped. It is useful when the natural direction of a design is from the base system back to a display or input system. | function coordinate_scale2d_cpc | ( | c | , |
| r | , | ||
| t | = false |
||
| ) |
Radially scale a list of 2d cartesian coordinates.
| c | <points-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 | ( | c | , |
| r | , | ||
| t | = false |
||
| ) |
Radially scale and convert a list of 2d polar coordinates to cartesian.
| c | <points-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 | <points-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 | ( | c | , |
| r | , | ||
| t | = false |
||
| ) |
Spherically scale and convert a list of 3d spherical coordinates to cartesian.
| c | <points-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.
| coordinate_unit_base = "c" |
<string> The base units for value storage.
to parameter will convert to this system. Definition at line 855 of file coordinate.scad.
| coordinate_unit_default = "c" |
<string> The default units when unspecified.
from or s parameter will assume this system. Definition at line 861 of file coordinate.scad.
| coordinate_positive_angle = true |
<boolean> When converting to angular measures add 360 to negative angles.
aa produced during conversion is shifted by +360° so that aa is always in [0°, 360°). Applies to polar, cylindrical, and spherical output. May be changed between individual calls; does not affect the polar angle pa. Definition at line 868 of file coordinate.scad.