From: Ian Jackson Date: Fri, 20 Oct 2017 17:01:07 +0000 (+0100) Subject: poster-tube-lid-parametric: wip X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=e67626c2133b0f816dae598ff0a6d2ef7e7975d3;p=reprap-play.git poster-tube-lid-parametric: wip --- diff --git a/poster-tube-lid-parametric.pl b/poster-tube-lid-parametric.pl old mode 100644 new mode 100755 index bc77bff..2c14993 --- a/poster-tube-lid-parametric.pl +++ b/poster-tube-lid-parametric.pl @@ -3,6 +3,8 @@ use strict; use Math::Vector::Real; +sub TAU () { PI*2; } + my $thick = 4; my $small_dia = 20; @@ -108,9 +110,72 @@ sub point ($$) { } else { die "$jp ?"; } - return $i_offset + $i_outward * $j_x + [0,0,1] * $j_y; } + +sub get_sections_ptvals { + my $last_name; + my @out; + while (defined my $name = shift @_) { + if ($name eq '|') { + push @out, [ $last_name, 1.0 ]; + } else { + my $count = shift @_; + foreach (my $ix = 0; $ix < $count; $ix++) { + push @out, [ $name, $ix/$count ]; + } + $last_name = $name; + } + } +} + +our @points; +our %point_indices; +our @triangles; + +sub triangle { + my @pixs; + foreach my $pval (@_) { + my $pix = $point_indices{$pval} + //= ((push @points, $pval), $#points); + return if grep { $pix eq $_ } @pixs + push @pixs, $pix; + } + push @triangles, \@pixs; +} + +sub make_sheet () { + my @ipts = get_sections_ptvals(@i_sections); + my @jpts = get_sections_ptvals(@j_sections); + my @sheet; + foreach my $ipt (@ipts) { + my @row = (); + foreach my $jpt (@jpts) { + push @row, &point @$ipt, @$jpt; + } + push @sheet, \@row; + } + foreach (my $qi=0; $qi<$#ipts; $qi++) { # i direction does not wrap + my $qi2 = $qi+1; + foreach (my $qj=0; $qj<@jpts; $qj++) { # j direction does wrap + my $qj2 = ($qj+1) % @jpts; + my $p0 = $sheet[$qi][$qj]; + triangle($p0, $sheet[$qi2][$qj], $sheet[$qi2][$qj2]); + triangle($p0, $sheet[$qi2][$qj2], $sheet[$qi2][$qj2]); + } + } +} + +sub write_out ($) { + print "polyhedron(points=[\n" or die $!; + print $_,",\n" or die $! foreach @points; + print "],triangles=[\n" or die $!; + print $_,",\n" or die $! foreach @triangles; + print "],convexity=10)\n" or die $!; +} + +make_sheet(); +write_out();