mirror of
https://github.com/nophead/NopSCADlib.git
synced 2025-09-01 03:21:53 +02:00
changes after review
This commit is contained in:
@@ -41,8 +41,8 @@ function rounded_polygon_arcs(points, tangents) = //! Compute the arcs at the po
|
||||
len = len(points)
|
||||
) [ for (i = [0: len-1])
|
||||
let(
|
||||
p1 = tangents[(i - 1 + len) % len].y,
|
||||
p2 = tangents[i].x,
|
||||
p1 = tangents[(i - 1 + len) % len][1],
|
||||
p2 = tangents[i][0],
|
||||
p = points[i],
|
||||
v1 = p1 - p,
|
||||
v2 = p2 - p,
|
||||
@@ -57,44 +57,23 @@ function rounded_polygon_arcs(points, tangents) = //! Compute the arcs at the po
|
||||
) [a, v, l]
|
||||
];
|
||||
|
||||
// we might want to remove the old rounded_polygon_tangents and to change rounded_polygon_length to use the v2 tangents
|
||||
function rounded_polygon_tangents_v2(points) = //! Compute the straight sections between a point and the next point, for each section [start_point, end_point, length]
|
||||
function rounded_polygon_tangents(points) = //! Compute the straight sections between a point and the next point, for each section [start_point, end_point, length]
|
||||
let(len = len(points))
|
||||
[ for(i = [0 : len - 1])
|
||||
let(ends = circle_tangent(points[i], points[(i + 1) % len]))
|
||||
[ends.x, ends.y, norm(ends.x - ends.y)]
|
||||
[ends[0], ends[1], norm(ends[0] - ends[1])]
|
||||
];
|
||||
|
||||
function rounded_polygon_tangents(points) = //! Compute the straight sections between a point and the next point, needed to draw and to compute the lengths
|
||||
let(len = len(points))
|
||||
[for(i = [0 : len - 1])
|
||||
let(ends = circle_tangent(points[i], points[(i + 1) % len]))
|
||||
for(end = [0, 1])
|
||||
ends[end]];
|
||||
|
||||
//function sumv(v, i = 0, sum = 0) = i == len(v) ? sum : sumv(v, i + 1, sum + v[i]); // moved to maths.scad
|
||||
|
||||
// the cross product of 2D vectors is the area of the parallelogram between them. We use the sign of this to decide if the angle is bigger than 180.
|
||||
function rounded_polygon_length(points, tangents) = //! Calculate the length given the point list and the list of tangents computed by ` rounded_polygon_tangents`
|
||||
let(
|
||||
len = len(points),
|
||||
indices = [0 : len - 1],
|
||||
straights = [for(i = indices) norm(tangents[2 * i] - tangents[2 * i + 1])],
|
||||
arcs = [for(i = indices) let(p1 = tangents[2 * i + 1],
|
||||
p2 = tangents[(2 * i + 2) % (2 * len)],
|
||||
corner = points[(i + 1) % len],
|
||||
c = [corner.x, corner.y],
|
||||
v1 = p1 - c,
|
||||
v2 = p2 - c,
|
||||
r = abs(corner.z),
|
||||
a = acos((v1 * v2) / sqr(r))) r ? PI * (cross(v1, v2) <= 0 ? a : 360 - a) * r / 180 : 0]
|
||||
)
|
||||
sumv(concat(straights, arcs));
|
||||
arcs = rounded_polygon_arcs(points, tangents)
|
||||
) sumv( map( concat(tangents, arcs), function(e) e[2] ) );
|
||||
|
||||
module rounded_polygon(points, _tangents = undef) { //! Draw the rounded polygon from the point list, can pass the tangent list to save it being calculated
|
||||
len = len(points);
|
||||
indices = [0 : len - 1];
|
||||
tangents = _tangents ? _tangents : rounded_polygon_tangents(points);
|
||||
tangents = [ for (t = _tangents ? _tangents : rounded_polygon_tangents(points)) each [t.x, t.y] ];
|
||||
|
||||
difference(convexity = points) {
|
||||
union() {
|
||||
|
Reference in New Issue
Block a user