1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-16 11:44:50 +02:00
This commit is contained in:
Justin Lin
2020-01-26 20:28:44 +08:00
parent 65f297070f
commit a49b27ecb1
3 changed files with 54 additions and 49 deletions

View File

@@ -0,0 +1,50 @@
function _px_cylinder_px_circle(radius, filled, thickness) =
let(range = [-radius: radius - 1])
filled ? [
for(y = range)
for(x = range)
let(v = [x, y])
if(norm(v) < radius) v
] :
let(ishell = radius * radius - 2 * thickness * radius)
[
for(y = range)
for(x = range)
let(
v = [x, y],
leng = norm(v)
)
if(leng < radius && (leng * leng) > ishell) v
];
function _px_cylinder_diff_r(r, h, filled, thickness) =
let(
r1 = r[0],
r2 = r[1]
)
r1 == r2 ? _px_cylinder_same_r(r1, h, filled, thickness) :
let(dr = (r2 - r1) / (h - 1))
[
for(i = 0; i < h; i = i + 1)
let(r = round(r1 + dr * i))
each [
for(pt = _px_cylinder_px_circle(r, filled, thickness))
[pt[0], pt[1], i]
]
];
function _px_cylinder_same_r(r, h, filled, thickness) =
let(c = _px_cylinder_px_circle(r, filled, thickness))
[
for(i = 0; i < h; i = i + 1)
each [
for(pt = c)
[pt[0], pt[1], i]
]
];
function _px_cylinder_impl(r, h, filled, thickness) =
is_num(r) ?
_px_cylinder_same_r(r, h, filled, thickness) :
_px_cylinder_diff_r(r, h, filled, thickness);

View File

@@ -8,52 +8,7 @@
*
**/
function _px_cylinder_px_circle(radius, filled, thickness) =
let(range = [-radius: radius - 1])
filled ? [
for(y = range)
for(x = range)
let(v = [x, y])
if(norm(v) < radius) v
] :
let(ishell = radius * radius - 2 * thickness * radius)
[
for(y = range)
for(x = range)
let(
v = [x, y],
leng = norm(v)
)
if(leng < radius && (leng * leng) > ishell) v
];
function _px_cylinder_diff_r(r, h, filled, thickness) =
let(
r1 = r[0],
r2 = r[1]
)
r1 == r2 ? _px_cylinder_same_r(r1, h, filled, thickness) :
let(dr = (r2 - r1) / (h - 1))
[
for(i = 0; i < h; i = i + 1)
let(r = round(r1 + dr * i))
each [
for(pt = _px_cylinder_px_circle(r, filled, thickness))
[pt[0], pt[1], i]
]
];
function _px_cylinder_same_r(r, h, filled, thickness) =
let(c = _px_cylinder_px_circle(r, filled, thickness))
[
for(i = 0; i < h; i = i + 1)
each [
for(pt = c)
[pt[0], pt[1], i]
]
];
use <pixel/_impl/_px_cylinder_impl.scad>;
function px_cylinder(r, h, filled = false, thickness = 1) =
is_num(r) ?
_px_cylinder_same_r(r, h, filled, thickness) :
_px_cylinder_diff_r(r, h, filled, thickness);
_px_cylinder_impl(r, h, filled, thickness);

View File

@@ -1,5 +1,5 @@
include <unittest.scad>;
include <pixel/px_cylinder.scad>;
use <unittest.scad>;
use <pixel/px_cylinder.scad>;
module test_px_cylinder() {
echo("==== test_px_cylinder ====");