1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-07-31 20:10:36 +02:00

add polar_coordinate

This commit is contained in:
Justin Lin
2021-02-13 10:56:11 +08:00
parent ac7711a827
commit 9aebfe8e11
3 changed files with 29 additions and 1 deletions

View File

@@ -144,7 +144,7 @@ These examples incubate dotSCAD and dotSCAD refactors these examples. See [examp
- [util/has](https://openhome.cc/eGossip/OpenSCAD/lib3x-has.html)
- [util/lerp](https://openhome.cc/eGossip/OpenSCAD/lib3x-lerp.html)
- [util/parse_number](https://openhome.cc/eGossip/OpenSCAD/lib3x-parse_number.html)
- util/polar_coordinate
- [util/polar_coordinate](https://openhome.cc/eGossip/OpenSCAD/lib3x-polar_coordinate.html)
- [util/radians](https://openhome.cc/eGossip/OpenSCAD/lib3x-radians.html)
- [util/rand](https://openhome.cc/eGossip/OpenSCAD/lib3x-rand.html)
- [util/reverse](https://openhome.cc/eGossip/OpenSCAD/lib3x-reverse.html)

View File

@@ -0,0 +1,18 @@
# polar_coordinate
Converts from Cartesian to Polar coordinates.
**Since:** 3.0
## Parameters
- `point` : The Cartesian coordinates (also called rectangular coordinates) of a point.
## Examples
use <util/polar_coordinate.scad>;
coord = polar_coordinate([100, 100]);
r = round(coord[0]);
theta = round(coord[1]);
assert([r, theta] == [141, 45]);

View File

@@ -1,3 +1,13 @@
/**
* polar_coordinate.scad
*
* @copyright Justin Lin, 2020
* @license https://opensource.org/licenses/lgpl-3.0.html
*
* @see https://openhome.cc/eGossip/OpenSCAD/lib3x-polar_coordinate.html
*
**/
use <../__comm__/__angy_angz.scad>;
function polar_coordinate(point) = [norm(point), atan2(point[1], point[0])]; // r, theta