mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-01 09:49:45 +00:00
Various fixes to get example generation working.
This commit is contained in:
parent
ea88aa8ac2
commit
35e6fdb1aa
3 changed files with 158 additions and 146 deletions
|
@ -1020,7 +1020,7 @@ function projection_on_plane(plane, points) =
|
||||||
: points,
|
: points,
|
||||||
plane = normalize_plane(plane),
|
plane = normalize_plane(plane),
|
||||||
n = point3d(plane)
|
n = point3d(plane)
|
||||||
)
|
)
|
||||||
[for(pi=p) pi - (pi*n - plane[3])*n];
|
[for(pi=p) pi - (pi*n - plane[3])*n];
|
||||||
|
|
||||||
|
|
||||||
|
@ -1069,7 +1069,7 @@ function closest_point_on_plane(plane, point) =
|
||||||
let( plane = normalize_plane(plane),
|
let( plane = normalize_plane(plane),
|
||||||
n = point3d(plane),
|
n = point3d(plane),
|
||||||
d = n*point - plane[3] // distance from plane
|
d = n*point - plane[3] // distance from plane
|
||||||
)
|
)
|
||||||
point - n*d;
|
point - n*d;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1113,7 +1113,7 @@ function plane_line_angle(plane, line) =
|
||||||
normal = plane_normal(plane),
|
normal = plane_normal(plane),
|
||||||
sin_angle = linedir*normal,
|
sin_angle = linedir*normal,
|
||||||
cos_angle = norm(cross(linedir,normal))
|
cos_angle = norm(cross(linedir,normal))
|
||||||
)
|
)
|
||||||
atan2(sin_angle,cos_angle);
|
atan2(sin_angle,cos_angle);
|
||||||
|
|
||||||
|
|
||||||
|
@ -1369,7 +1369,7 @@ function circle_2tangents(pt1, pt2, pt3, r, d, tangents=false) =
|
||||||
a = vector_angle(v1, v2),
|
a = vector_angle(v1, v2),
|
||||||
hyp = r / sin(a/2),
|
hyp = r / sin(a/2),
|
||||||
cp = pt2 + hyp * vmid
|
cp = pt2 + hyp * vmid
|
||||||
)
|
)
|
||||||
!tangents ? [cp, n] :
|
!tangents ? [cp, n] :
|
||||||
let(
|
let(
|
||||||
x = hyp * cos(a/2),
|
x = hyp * cos(a/2),
|
||||||
|
@ -1377,7 +1377,7 @@ function circle_2tangents(pt1, pt2, pt3, r, d, tangents=false) =
|
||||||
tp2 = pt2 + x * v2,
|
tp2 = pt2 + x * v2,
|
||||||
dang1 = vector_angle(tp1-cp,pt2-cp),
|
dang1 = vector_angle(tp1-cp,pt2-cp),
|
||||||
dang2 = vector_angle(tp2-cp,pt2-cp)
|
dang2 = vector_angle(tp2-cp,pt2-cp)
|
||||||
)
|
)
|
||||||
[cp, n, tp1, tp2, dang1, dang2];
|
[cp, n, tp1, tp2, dang1, dang2];
|
||||||
|
|
||||||
module circle_2tangents(pt1, pt2, pt3, r, d, h, center=false) {
|
module circle_2tangents(pt1, pt2, pt3, r, d, h, center=false) {
|
||||||
|
@ -1678,14 +1678,23 @@ function furthest_point(pt, points) =
|
||||||
function polygon_area(poly, signed=false) =
|
function polygon_area(poly, signed=false) =
|
||||||
assert(is_path(poly), "Invalid polygon." )
|
assert(is_path(poly), "Invalid polygon." )
|
||||||
len(poly)<3 ? 0 :
|
len(poly)<3 ? 0 :
|
||||||
|
let( cpoly = close_path(simplify_path(poly)) )
|
||||||
len(poly[0])==2
|
len(poly[0])==2
|
||||||
? sum([for(i=[1:1:len(poly)-2]) cross(poly[i]-poly[0],poly[i+1]-poly[0]) ])/2
|
? sum([for(i=[1:1:len(poly)-2]) cross(poly[i]-poly[0],poly[i+1]-poly[0]) ])/2
|
||||||
: let( plane = plane_from_points(poly) )
|
: let( plane = plane_from_points(poly) )
|
||||||
plane==undef? undef :
|
plane==undef? undef :
|
||||||
let( n = unit(plane_normal(plane)),
|
let(
|
||||||
total = sum([for(i=[1:1:len(poly)-1]) cross(poly[i]-poly[0],poly[i+1]-poly[0])*n ])/2
|
n = unit(plane_normal(plane)),
|
||||||
)
|
total = sum([
|
||||||
signed ? total : abs(total);
|
for(i=[1:1:len(cpoly)-2])
|
||||||
|
let(
|
||||||
|
v1 = cpoly[i] - cpoly[0],
|
||||||
|
v2 = cpoly[i+1] - cpoly[0]
|
||||||
|
)
|
||||||
|
cross(v1,v2) * n
|
||||||
|
])/2
|
||||||
|
)
|
||||||
|
signed ? total : abs(total);
|
||||||
|
|
||||||
|
|
||||||
// Function: is_convex_polygon()
|
// Function: is_convex_polygon()
|
||||||
|
@ -2082,9 +2091,8 @@ function _split_polygon_at_z(poly, z) =
|
||||||
// polys = A list of 3D polygons to split.
|
// polys = A list of 3D polygons to split.
|
||||||
// xs = A list of scalar X values to split at.
|
// xs = A list of scalar X values to split at.
|
||||||
function split_polygons_at_each_x(polys, xs, _i=0) =
|
function split_polygons_at_each_x(polys, xs, _i=0) =
|
||||||
assert( is_consistent(polys) && is_path(poly[0],dim=3) ,
|
assert( [for (poly=polys) if (!is_path(poly,3)) 1] == [], "Expects list of 3D paths.")
|
||||||
"The input list should contains only 3D polygons." )
|
assert( is_vector(xs), "The split value list should contain only numbers." )
|
||||||
assert( is_finite(xs), "The split value list should contain only numbers." )
|
|
||||||
_i>=len(xs)? polys :
|
_i>=len(xs)? polys :
|
||||||
split_polygons_at_each_x(
|
split_polygons_at_each_x(
|
||||||
[
|
[
|
||||||
|
@ -2103,9 +2111,8 @@ function split_polygons_at_each_x(polys, xs, _i=0) =
|
||||||
// polys = A list of 3D polygons to split.
|
// polys = A list of 3D polygons to split.
|
||||||
// ys = A list of scalar Y values to split at.
|
// ys = A list of scalar Y values to split at.
|
||||||
function split_polygons_at_each_y(polys, ys, _i=0) =
|
function split_polygons_at_each_y(polys, ys, _i=0) =
|
||||||
// assert( is_consistent(polys) && is_path(polys[0],dim=3) , // not all polygons should have the same length!!!
|
assert( [for (poly=polys) if (!is_path(poly,3)) 1] == [], "Expects list of 3D paths.")
|
||||||
// "The input list should contains only 3D polygons." )
|
assert( is_vector(ys), "The split value list should contain only numbers." )
|
||||||
assert( is_finite(ys) || is_vector(ys), "The split value list should contain only numbers." ) //***
|
|
||||||
_i>=len(ys)? polys :
|
_i>=len(ys)? polys :
|
||||||
split_polygons_at_each_y(
|
split_polygons_at_each_y(
|
||||||
[
|
[
|
||||||
|
@ -2124,9 +2131,8 @@ function split_polygons_at_each_y(polys, ys, _i=0) =
|
||||||
// polys = A list of 3D polygons to split.
|
// polys = A list of 3D polygons to split.
|
||||||
// zs = A list of scalar Z values to split at.
|
// zs = A list of scalar Z values to split at.
|
||||||
function split_polygons_at_each_z(polys, zs, _i=0) =
|
function split_polygons_at_each_z(polys, zs, _i=0) =
|
||||||
assert( is_consistent(polys) && is_path(poly[0],dim=3) ,
|
assert( [for (poly=polys) if (!is_path(poly,3)) 1] == [], "Expects list of 3D paths.")
|
||||||
"The input list should contains only 3D polygons." )
|
assert( is_vector(zs), "The split value list should contain only numbers." )
|
||||||
assert( is_finite(zs), "The split value list should contain only numbers." )
|
|
||||||
_i>=len(zs)? polys :
|
_i>=len(zs)? polys :
|
||||||
split_polygons_at_each_z(
|
split_polygons_at_each_z(
|
||||||
[
|
[
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
BOSL_VERSION = [2,0,479];
|
BOSL_VERSION = [2,0,480];
|
||||||
|
|
||||||
|
|
||||||
// Section: BOSL Library Version Functions
|
// Section: BOSL Library Version Functions
|
||||||
|
|
14
vnf.scad
14
vnf.scad
|
@ -672,8 +672,11 @@ function vnf_validate(vnf, show_warns=true, check_isects=false) =
|
||||||
],
|
],
|
||||||
nonplanars = unique([
|
nonplanars = unique([
|
||||||
for (face = faces) let(
|
for (face = faces) let(
|
||||||
faceverts = [for (k=face) varr[k]]
|
faceverts = [for (k=face) varr[k]],
|
||||||
) if (!coplanar(faceverts)) [
|
area = polygon_area(faceverts)
|
||||||
|
)
|
||||||
|
if (is_num(area) && abs(area) > EPSILON)
|
||||||
|
if (!coplanar(faceverts)) [
|
||||||
"ERROR",
|
"ERROR",
|
||||||
"NONPLANAR",
|
"NONPLANAR",
|
||||||
"Face vertices are not coplanar",
|
"Face vertices are not coplanar",
|
||||||
|
@ -712,9 +715,12 @@ function vnf_validate(vnf, show_warns=true, check_isects=false) =
|
||||||
if (v!=edge[0] && v!=edge[1]) let(
|
if (v!=edge[0] && v!=edge[1]) let(
|
||||||
a = varr[edge[0]],
|
a = varr[edge[0]],
|
||||||
b = varr[v],
|
b = varr[v],
|
||||||
c = varr[edge[1]],
|
c = varr[edge[1]]
|
||||||
|
)
|
||||||
|
if (a != b && b != c && a != c) let(
|
||||||
pt = segment_closest_point([a,c],b)
|
pt = segment_closest_point([a,c],b)
|
||||||
) if (pt == b) [
|
)
|
||||||
|
if (pt == b) [
|
||||||
"ERROR",
|
"ERROR",
|
||||||
"T_JUNCTION",
|
"T_JUNCTION",
|
||||||
"Vertex is mid-edge on another Face",
|
"Vertex is mid-edge on another Face",
|
||||||
|
|
Loading…
Reference in a new issue