add region centroid capability and consolidate into one centroid

function for polygons, regions and VNFs.
Fix bug with anchors for linear_sweep (due to centerpoint issues)
Fix intersection anchors for vnfs when anchor vector intersects
in a path instead of a single point.
This commit is contained in:
Adrian Mariano
2021-10-20 22:44:55 -04:00
parent a7ca1b1b64
commit 76272d9d9a
10 changed files with 158 additions and 101 deletions

View File

@@ -278,12 +278,12 @@
// Example(FlatSpin,VPD=32,VPT=[1.2,4.3,2]): Another "distance" example:
// off = [0,2];
// shape = turtle(["right",45,"move", "left",45,"move", "left",45, "move", "jump", [.5+sqrt(2)/2,8]]);
// rshape = rot(180,cp=polygon_centroid(shape)+off, p=shape);
// rshape = rot(180,cp=centroid(shape)+off, p=shape);
// skin([shape,rshape],z=[0,4], method="distance",slices=10,refine=15);
// Example(FlatSpin,VPD=32,VPT=[1.2,4.3,2]): Slightly shifting the profile changes the optimal linkage
// off = [0,1];
// shape = turtle(["right",45,"move", "left",45,"move", "left",45, "move", "jump", [.5+sqrt(2)/2,8]]);
// rshape = rot(180,cp=polygon_centroid(shape)+off, p=shape);
// rshape = rot(180,cp=centroid(shape)+off, p=shape);
// skin([shape,rshape],z=[0,4], method="distance",slices=10,refine=15);
// Example(FlatSpin,VPD=444,VPT=[0,0,50]): This optimal solution doesn't look terrible:
// prof1 = path3d([[-50,-50], [-50,50], [50,50], [25,25], [50,0], [25,-25], [50,-50]]);
@@ -386,7 +386,7 @@ module skin(profiles, slices, refine=1, method="direct", sampling, caps, closed=
anchor="origin",cp,spin=0, orient=UP, extent=false)
{
vnf = skin(profiles, slices, refine, method, sampling, caps, closed, z, style=style);
attachable(anchor=anchor, spin=spin, orient=orient, vnf=vnf, extent=extent, cp=is_def(cp) ? cp : vnf_centroid(vnf))
attachable(anchor=anchor, spin=spin, orient=orient, vnf=vnf, extent=extent, cp=is_def(cp) ? cp : centroid(vnf))
{
vnf_polyhedron(vnf,convexity=convexity);
children();
@@ -816,7 +816,7 @@ module path_sweep(shape, path, method="incremental", normal, closed=false, twist
{
vnf = path_sweep(shape, path, method, normal, closed, twist, twist_by_length,
symmetry, last_normal, tangent, relaxed, caps, style);
attachable(anchor=anchor, spin=spin, orient=orient, vnf=vnf, extent=extent, cp=is_def(cp) ? cp : vnf_centroid(vnf))
attachable(anchor=anchor, spin=spin, orient=orient, vnf=vnf, extent=extent, cp=is_def(cp) ? cp : centroid(vnf))
{
vnf_polyhedron(vnf,convexity=convexity);
children();
@@ -1001,7 +1001,7 @@ module path_sweep2d(profile, path, closed=false, caps, quality=1, style="min_edg
anchor="origin", cp, spin=0, orient=UP, extent=false)
{
vnf = path_sweep2d(profile, path, closed, caps, quality, style);
attachable(anchor=anchor, spin=spin, orient=orient, vnf=vnf, extent=extent, cp=is_def(cp) ? cp : vnf_centroid(vnf))
attachable(anchor=anchor, spin=spin, orient=orient, vnf=vnf, extent=extent, cp=is_def(cp) ? cp : centroid(vnf))
{
vnf_polyhedron(vnf,convexity=convexity);
children();
@@ -1128,7 +1128,7 @@ module sweep(shape, transforms, closed=false, caps, style="min_edge", convexity=
anchor="origin",cp,spin=0, orient=UP, extent=false)
{
vnf = sweep(shape, transforms, closed, caps, style);
attachable(anchor=anchor, spin=spin, orient=orient, vnf=vnf, extent=extent, cp=is_def(cp) ? cp : vnf_centroid(vnf))
attachable(anchor=anchor, spin=spin, orient=orient, vnf=vnf, extent=extent, cp=is_def(cp) ? cp : centroid(vnf))
{
vnf_polyhedron(vnf,convexity=convexity);
children();
@@ -1591,7 +1591,7 @@ function _skin_tangent_match(poly1, poly2) =
swap = len(poly1)>len(poly2),
big = swap ? poly1 : poly2,
small = swap ? poly2 : poly1,
curve_offset = polygon_centroid(small)-polygon_centroid(big),
curve_offset = centroid(small)-centroid(big),
cutpts = [for(i=[0:len(small)-1]) _find_one_tangent(big, select(small,i,i+1),curve_offset=curve_offset)],
shift = last(cutpts)+1,
newbig = polygon_shift(big, shift),