use Math::Vector::Real;
+sub TAU () { PI*2; }
+
my $thick = 4;
my $small_dia = 20;
} 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();