33 include <math-base.scad>;
71 for (ip = [
for (fi = f)
for (ai =
nssequence(fi, n=2, s=1, w=
true)) ai])
129 ? [for (j = ax) [for (m = f) for (i=[0 : len(m)-1]) c[m[i]][j]]]
130 : [for (j = ax) [for (i = c) i[j]]],
132 b = [for (j = ax) [min(pm[j]), max(pm[j])] + [-ap[j]/2, +ap[j]/2]]
135 (s == true) ? b[j][1] - b[j][0] : [b[j][0], b[j][1]]
176 d = len([for (i=b) if (i != [undef, undef]) i])
179 [ [for (x=b[0], y=b[1], z=b[2]) [x, y, z]],
180 [[0,2,3,1], [4,0,1,5], [6,4,5,7], [2,6,7,3], [0,4,6,2], [3,7,5,1]] ]
181 : [ [for (x=b[0], y=b[1]) [x, y]],
257 for (fi = f) let (fn = len(fi))
279 ) = [for (fi = [0:len(f)-1]) if (
exists(i, f[fi])) fi];
304 for (fi = [0:len(f)-1])
404 pc = [for (i = [0:2]) let (p = c[ci[i]]) (len(p) == 3) ? p : [p[0], p[1], 0]]
406 cross(pc[0]-pc[1], pc[2]-pc[1]) * ((cw == true) ? 1 : -1);
438 pc = [for (i = ci) c[i]]
499 ) = [for (fi=f) len(fi)];
522 for (i=[0 : len(f)-1])
525 n1 =
cross_ll([c[f[i][0]], c[f[i][1]]], [c[f[i][0]], c[f[i][2]]]),
526 af = [for (v=f[i]) for (j=[0 : len(f)-1]) if (j != i &&
exists(v, f[j])) j]
531 n2 =
cross_ll([c[f[u][0]], c[f[u][1]]], [c[f[u][0]], c[f[u][2]]])
566 for (k=[for (j=f) for (i=
nssequence(j, n=3, s=1, w=true)) i])
567 angle_ll([c[k[0]], c[k[1]]], [c[k[1]], c[k[2]]])
603 ((len(ul) == 1) && (len(ua) == 1));
629 for (ci = [1 : len(fi)-2]) [fi[0], fi[ci], fi[ci+1]]
663 for (k = pm) let (n = len(k))
664 for (i=[0 : n-1]) let (j = (i == 0) ? n-1 : i-1)
704 for (k = pm) let (n = len(k))
705 for (i=[0 : n-1]) let (j = (i == 0) ? n-1 : i-1)
706 (c[k[j]][0] + c[k[i]][0]) * (c[k[i]][1] - c[k[j]][1])
711 (s == false) ? abs(sa) : sa;
748 ac = [abs(nv[0]), abs(nv[1]), abs(nv[2])],
750 ai = (am == ac[2]) ? 2 : (am == ac[1]) ? 1 : 0,
753 for (k = pm) let (m = len(k))
755 c[k[i%m]][(ai+1)%3] * (c[k[(i+1)%m]][(ai+2)%3] - c[k[(i-1)%m]][(ai+2)%3])
794 for (k = pm) let (n = len(k))
798 j = (i == 0) ? n-1 : i-1,
808 [(xc + xn) * cd, (yc + yn) * cd]
875 for (k = pm) let (n = len(k))
877 sign(
cross_ll([c[k[i]], c[k[(i+1)%n]]], [c[k[(i+1)%n]], c[k[(i+2)%n]]]))
931 for (k = pm) let (n = len(k))
935 j = (i == 0) ? n-1 : i-1,
938 (c[k[j]][1] <= t[1]) && (c[k[i]][1] > t[1])
942 (c[k[j]][1] > t[1]) && (c[k[i]][1] <= t[1])
1013 for (k = pm) let (n = len(k))
1017 j = (i == 0) ? n-1 : i-1
1019 angle_ll([t, c[k[i]]], [t, c[k[j]]])
1076 (len(fi) != 3) ? undef
1173 pn = len([for (pi = pm) for (ci = pi) 1]),
1176 zr = (center == true) ? [-h/2, h/2] : [0, h],
1180 pp = [for (zi = zr) for (pi = pm) for (ci = pi) concat(c[ci] - po, zi)],
1183 [for (pi = pm) for (ci = pi) ci],
1184 [for (pi = pm) for (cn = [len(pi)-1 : -1 : 0]) pi[cn] + pn],
1185 for (pi = pm) for (ci = pi)
1187 ? [ci, ci+pn, (ci+1)%pn+pn, (ci+1)%pn]
1188 : [ci, (ci+1)%pn, (ci+1)%pn+pn, ci+pn]
function polytope_line(c, f, e, i, l, r=false)
Get a line from an edge or any two vetices of a polytope.
function polytope_face_angles(c, f)
List the angles between all adjacent faces of a polyhedron.
function polyhedron_area(c, f)
Compute the surface area of a polyhedron in a Euclidean 3d-space.
function is_left_ppp(p1, p2, p3)
Test if a point is left, on, or right of an infinite line in a Euclidean 2d-space.
function distance_pp(p1, p2)
Compute the distance between two Euclidean points.
function polytope_edge_n(c, f, e, i)
Get a normal vector for a polytope edge.
function polygon2d_centroid(c, p)
Compute the center of mass of a polygon in a Euclidean 2d-space.
function cross_ll(l1, l2)
Compute the cross product of two lines (or vectors) in a Euclidean 3d or 2d-space.
function mean(v)
Compute the mean/average of a list of numbers.
function polytope_vertex_n(c, f, i)
Get a normal vector for a polytope vertex.
function nssequence(v, n=1, s=1, w=false)
Return a list of all n-element sequential-subsets of an iterable value.
function defined_or(v, d)
Return a value when it is defined or a default value when it is not.
function linear_extrude_pp2pf(c, p, h=1, centroid=false, center=false)
Convert a polygon to a polyhedron by adding a height dimension.
function is_integer(v)
Test if a value is an integer.
function polytope_edge_lengths(c, e)
List the edge lengths of a polytope.
function second(v)
Return the second element of an iterable value.
function sum(v, i1, i2)
Compute the sum of a list of numbers.
function unique(v)
Return the unique elements of an iterable value.
function all_len(v, l)
Test if all elements of a list of values are lists of a specified length.
function is_scalar(v)
Test if a value is a single non-iterable value.
function polytope_faces_are_regular(c, f, e, d=6)
Test if the faces of a polytope are all regular.
function polytope_edge_af(f, e, i)
List the adjacent face indexes for a polytope edge.
function edefined_or(v, i, d)
Return an iterable element when it exists or a default value when it does not.
function polytope_bbox_pf(c, f, a)
Generate a bounding box polytope for another polytope in 3d or 2d.
function polyhedron_volume_tf(c, f)
Compute the volume of a triangulated polyhedron in a Euclidean 3d-space.
function polytope_face_m(c, f, i, l)
Get the mean coordinate of all vertices of a polytope face.
function polygon2d_is_cw(c, p)
Test the vertex ordering of a polygon in a Euclidean 2d-space.
function polytope_triangulate_ft(f)
Triangulate the faces of a convex polytope using fan triangulation.
function not_defined(v)
Test if a value is not defined.
function exists(mv, v, s=true, i)
Check for the existence of a match value in an iterable value.
function polyhedron_centroid_tf(c, f)
Compute the center of mass of a triangulated polyhedron in a Euclidean 3d-space.
function unit_l(l)
Compute the normalized unit vector of a Euclidean line (or vector).
function is_defined(v)
Test if a value is defined.
function polytope_plane(c, f, i, l, cw=true)
Get a plane for a polytope face.
function polytope_vertex_af(f, i)
List the adjacent face indexes for a polytope vertex.
function is_range(v)
Test if a value is a range definition.
function angle_ll(l1, l2)
Compute the angle between two lines (or vectors) in a Euclidean 3d or 2d-space.
function sround(v, d=6)
Round all numerical values of a list to a fixed number of significant figures.
function is_list(v)
Test if a value is an iterable list of values.
function first(v)
Return the first element of an iterable value.
function polygon2d_perimeter(c, p)
Calculate the perimeter length of a polygon in 2d.
function polytope_faces2edges(f)
List the edge coordinate index pairs of a polytope.
function polygon2d_is_convex(c, p)
Test the convexity of a polygon in a Euclidean 2d-space.
function polytope_face_vcounts(f)
List the vertex counts for all polytope faces.
function polytope_face_mn(c, f, i, l, cw=true)
Get the mean coordinate and normal vector of a polytope face.
function polygon2d_is_pip_wn(c, p, t)
Test if a point is inside a polygon in a Euclidean 2d-space using winding number. ...
function circular_index(i, l, f=0)
Map an index position into a circularly indexed list.
function consts(l, v, u=false)
Create a sequence of constant or incrementing elements.
function polytope_face_n(c, f, i, l, cw=true)
Get the normal vector of a polytope face.
function polygon2d_area(c, p, s=false)
Compute the signed area of a polygon in a Euclidean 2d-space.
function polytope_limits(c, f, a, d=[0:2], s=true)
Determine the bounding limits of a polytope.
function polytope_edge_angles(c, f)
List the adjacent edge angles for each polytope vertex.
function polygon2d_is_pip_as(c, p, t)
Test if a point is inside a polygon in a Euclidean 2d-space using angle summation.
function polygon3d_area(c, p, n)
Compute the area of a polygon in a Euclidean 3d-space.
function polygon2d_winding(c, p, t)
Compute the winding number of a polygon about a point in a Euclidean 2d-space.
function polytope_vertex_av(f, i)
List the adjacent vertices for a given polytope vertex.