mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-09 08:16:50 +02:00
refactored
This commit is contained in:
40
src/__private__/__shape_arc.scad
Normal file
40
src/__private__/__shape_arc.scad
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
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 __shape_arc(radius, angle, width, width_mode = "LINE_CROSS") =
|
||||||
|
let(
|
||||||
|
w_offset = width_mode == "LINE_CROSS" ? [width / 2, -width / 2] : (
|
||||||
|
width_mode == "LINE_INWARD" ? [0, -width] : [width, 0]
|
||||||
|
),
|
||||||
|
frags = __frags(radius),
|
||||||
|
a_step = 360 / frags,
|
||||||
|
half_a_step = a_step / 2,
|
||||||
|
angles = __is_vector(angle) ? angle : [0, angle],
|
||||||
|
m = floor(angles[0] / a_step) + 1,
|
||||||
|
n = floor(angles[1] / a_step),
|
||||||
|
r_outer = radius + w_offset[0],
|
||||||
|
r_inner = radius + w_offset[1],
|
||||||
|
points = concat(
|
||||||
|
// outer arc path
|
||||||
|
[__ra_to_xy(__edge_r_begin(r_outer, angles[0], a_step, m), angles[0])],
|
||||||
|
m > n ? [] : [
|
||||||
|
for(i = [m:n])
|
||||||
|
__ra_to_xy(r_outer, a_step * i)
|
||||||
|
],
|
||||||
|
angles[1] == a_step * n ? [] : [__ra_to_xy(__edge_r_end(r_outer, angles[1], a_step, n), angles[1])],
|
||||||
|
// inner arc path
|
||||||
|
angles[1] == a_step * n ? [] : [__ra_to_xy(__edge_r_end(r_inner, angles[1], a_step, n), angles[1])],
|
||||||
|
m > n ? [] : [
|
||||||
|
for(i = [m:n])
|
||||||
|
let(idx = (n + (m - i)))
|
||||||
|
__ra_to_xy(r_inner, a_step * idx)
|
||||||
|
|
||||||
|
],
|
||||||
|
[__ra_to_xy(__edge_r_begin(r_inner, angles[0], a_step, m), angles[0])]
|
||||||
|
)
|
||||||
|
) points;
|
@@ -15,44 +15,7 @@
|
|||||||
include <__private__/__frags.scad>;
|
include <__private__/__frags.scad>;
|
||||||
include <__private__/__is_vector.scad>;
|
include <__private__/__is_vector.scad>;
|
||||||
include <__private__/__ra_to_xy.scad>;
|
include <__private__/__ra_to_xy.scad>;
|
||||||
|
include <__private__/__shape_arc.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 shape_arc(radius, angle, width, width_mode = "LINE_CROSS") =
|
function shape_arc(radius, angle, width, width_mode = "LINE_CROSS") =
|
||||||
let(
|
__shape_arc(radius, angle, width, width_mode);
|
||||||
w_offset = width_mode == "LINE_CROSS" ? [width / 2, -width / 2] : (
|
|
||||||
width_mode == "LINE_INWARD" ? [0, -width] : [width, 0]
|
|
||||||
),
|
|
||||||
frags = __frags(radius),
|
|
||||||
a_step = 360 / frags,
|
|
||||||
half_a_step = a_step / 2,
|
|
||||||
angles = __is_vector(angle) ? angle : [0, angle],
|
|
||||||
m = floor(angles[0] / a_step) + 1,
|
|
||||||
n = floor(angles[1] / a_step),
|
|
||||||
r_outer = radius + w_offset[0],
|
|
||||||
r_inner = radius + w_offset[1],
|
|
||||||
points = concat(
|
|
||||||
// outer arc path
|
|
||||||
[__ra_to_xy(__edge_r_begin(r_outer, angles[0], a_step, m), angles[0])],
|
|
||||||
m > n ? [] : [
|
|
||||||
for(i = [m:n])
|
|
||||||
__ra_to_xy(r_outer, a_step * i)
|
|
||||||
],
|
|
||||||
angles[1] == a_step * n ? [] : [__ra_to_xy(__edge_r_end(r_outer, angles[1], a_step, n), angles[1])],
|
|
||||||
// inner arc path
|
|
||||||
angles[1] == a_step * n ? [] : [__ra_to_xy(__edge_r_end(r_inner, angles[1], a_step, n), angles[1])],
|
|
||||||
m > n ? [] : [
|
|
||||||
for(i = [m:n])
|
|
||||||
let(idx = (n + (m - i)))
|
|
||||||
__ra_to_xy(r_inner, a_step * idx)
|
|
||||||
|
|
||||||
],
|
|
||||||
[__ra_to_xy(__edge_r_begin(r_inner, angles[0], a_step, m), angles[0])]
|
|
||||||
)
|
|
||||||
) points;
|
|
Reference in New Issue
Block a user