1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-10 16:54:23 +02:00

add convex_offset

This commit is contained in:
Justin Lin
2021-07-09 20:13:09 +08:00
parent 1ad4d38dca
commit 738076131c

View File

@@ -0,0 +1,21 @@
use <triangle/tri_incenter.scad>;
function convex_offset(vertices, d) =
let(
c = tri_incenter(vertices),
leng_vertices = len(vertices)
)
[
for(i = [0:leng_vertices - 1])
let(
curr_p = vertices[i],
next_p = vertices[(i + 1) % leng_vertices],
v1 = c - curr_p,
v2 = next_p - curr_p,
leng_v1 = norm(v1),
leng_v2 = norm(v2),
a = acos((v1 * v2) / (leng_v1 * leng_v2)),
leng = -d / sin(a)
)
v1 / leng_v1 * leng + curr_p
];