X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=reprap-play.git;a=blobdiff_plain;f=poster-tube-lid-parametric.scad.pl;h=64d4d00ebe9f5b472789f5411155e6457b95d8ec;hp=bbe70d93ad7c195288fdbf1066ceedc62c748333;hb=c827170d69910df04bc8b620f2ed53ed5164e633;hpb=3ed022ffa2e274f8661e2927cff49d4e8bdafbe0 diff --git a/poster-tube-lid-parametric.scad.pl b/poster-tube-lid-parametric.scad.pl index bbe70d9..64d4d00 100755 --- a/poster-tube-lid-parametric.scad.pl +++ b/poster-tube-lid-parametric.scad.pl @@ -16,9 +16,9 @@ my $slope_angle = 45 * TAU/360; my $jcurverad = 5; my $tall = 50; -my $lin_len = 4; -my $sine_size = 10; -my $sine_angle = 1.2 * TAU/8; +my $lin_len = 2; +my $sine_size = 5; +my $sine_angle = 1.20 * TAU/8; my $ballend_xr = $thick/2; @@ -26,12 +26,10 @@ my $skew_slope = 0.7; my @i_sections = qw(ball0 -6 sine0 -10 - - - lin0 2 - circle 20 + lin0 -2 + circle 40 lin1 2 sine1 10 - - ball2 6 - ); @@ -49,11 +47,13 @@ my @j_sections = qw(lin0 2 sub point ($$$$) { my ($ip,$it, $jp,$jt) = @_; - my ($i_offset, $i_outward); + my ($i_offset); - $i_outward = V( 0, - ($ip =~ m/0$/ ? -1 : +1), - 0 ); + my $i_outward = V( 0, + ($ip =~ m/0$/ ? -1 : +1), + 0 ); + + my $i_j_y_angle = 0; my $i_thickscale = 1.0; my $sine_len = $sine_size * sin($sine_angle); @@ -70,22 +70,28 @@ sub point ($$$$) { 0 ); } elsif ($ip =~ m/^sine[01]$/) { my $angle = $it * $sine_angle; - $i_offset = V( -$sine_size * sin($angle) -$lin_len, + $i_offset = V( -$lin_len -$sine_size * sin($angle), 0, +$sine_size * (1 - cos($angle)) ); + $i_j_y_angle = $angle; } elsif ($ip =~ m/^ball[02]$/) { + $i_j_y_angle = $sine_angle; my $angle = $it * TAU/4; my $dx = sin($angle) * $ballend_xr; - $i_offset = V( -$lin_len -$sine_len - $dx, + $i_offset = V( -$lin_len -$sine_len - $dx * cos($sine_angle), 0, - +$sine_height + $dx * tan($sine_angle) + +$sine_height + $dx * sin($sine_angle) ); $i_thickscale = cos($angle); } else { die "$ip ?"; } + my $i_j_y_vect = V( sin($i_j_y_angle), + 0, + cos($i_j_y_angle )); + my $j_plus_th = $jp =~ m/2$/ ? $thick : 0; my $i_thick = $thick * $i_thickscale; @@ -122,18 +128,18 @@ sub point ($$$$) { die "$jp ?"; } - if ($i_offset->[0] < 0) { - my $base = $large_dia/2 + 3.0*($large_dia - $small_dia)/2; - $i_offset->[0] *= - ($base - $j_x) / - ($base - $small_dia/2); + $j_y -= $j_qrc_y; + + if ($j_y > 0) { + $i_j_y_vect = V(0,0,1); } # print STDERR "@_ $j_x $j_y $i_offset $i_outward\n"; return $i_offset + $j_x * $i_outward + - V(0,0,1) * $j_y + + $i_j_y_vect * $j_y + + V(0,0,1) * $j_qrc_y + V(0,0,-$tall) ; } @@ -163,20 +169,29 @@ our @points; our %point_indices; our @triangles; +my @ipts; +my @jpts; + +my $qi; +my $qj; + sub triangle { my @pixs; foreach my $pval (@_) { my $pix = $point_indices{$pval} //= ((push @points, $pval), $#points); - return if grep { $pix eq $_ } @pixs; + if (grep { $pix eq $_ } @pixs) { + print "// elide @{ $ipts[$qi] } @{ $jpts[$qj] }\n"; + return; + } push @pixs, $pix; } - push @triangles, \@pixs; + push @triangles, [ $qi,$qj, \@pixs ]; } sub make_sheet () { - my @ipts = get_sections_ptvals(@i_sections); - my @jpts = get_sections_ptvals(@j_sections); + @ipts = get_sections_ptvals(@i_sections); + @jpts = get_sections_ptvals(@j_sections); my @sheet; foreach my $ipt (@ipts) { my @row = (); @@ -185,9 +200,9 @@ sub make_sheet () { } push @sheet, \@row; } - foreach (my $qi=0; $qi<$#ipts; $qi++) { # i direction does not wrap + foreach ($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 + foreach ($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]); @@ -205,7 +220,9 @@ sub write_out () { print "module ImplHeadCup(){ polyhedron(points=[\n" or die $!; print pv($_),",\n" or die $! foreach @points; print "],faces=[\n" or die $!; - print pv($_),",\n" or die $! foreach @triangles; + foreach (@triangles) { + print pv($_->[2]),", // @{ $ipts[$_->[0]] } @{ $jpts[$_->[1]] }\n" or die $!; + } print "],convexity=10); }\n" or die $!; print <