1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-03-14 02:59:42 +01:00

add arc_path

This commit is contained in:
Justin Lin 2018-06-10 13:23:21 +08:00
parent e23c07f4b0
commit 3050bee1d1

39
src/arc_path.scad Normal file
View File

@ -0,0 +1,39 @@
/**
* arc_shape.scad
*
* Creates an arc. You can pass a 2 element vector to define the central angle.
* Its $fa, $fs and $fn parameters are consistent with the circle module.
* It depends on the circular_sector module so you have to include circular_sector.scad.
*
* @copyright Justin Lin, 2017
* @license https://opensource.org/licenses/lgpl-3.0.html
*
* @see https://openhome.cc/eGossip/OpenSCAD/lib-arc_shape.html
*
**/
include <__private__/__frags.scad>;
include <__private__/__is_vector.scad>;
include <__private__/__ra_to_xy.scad>;
function __edge_r_begin(orig_r, a, a_step, m) =
let(leng = orig_r * cos(a_step / 2))
leng / cos((m - 0.5) * a_step - a);
function __edge_r_end(orig_r, a, a_step, n) =
let(leng = orig_r * cos(a_step / 2))
leng / cos((n + 0.5) * a_step - a);
function arc_path(radius, angle) =
let(
frags = __frags(radius),
a_step = 360 / frags,
angles = __is_vector(angle) ? angle : [0, angle],
m = floor(angles[0] / a_step) + 1,
n = floor(angles[1] / a_step),
points = concat([__ra_to_xy(__edge_r_begin(radius, angles[0], a_step, m), angles[0])],
m > n ? [] : [
for(i = [m:n])
__ra_to_xy(radius, a_step * i)
])
) points;