4 use Math::Vector::Real;
21 my $ballend_xr = $thick/2;
23 my @i_sections = qw(ball0 6
32 my @j_sections = qw(lin0 2
43 my ($ip,$it, $jp,$jt) = @_;
45 my ($i_offset, $i_outward);
48 ($ip =~ m/0$/ ? -1 : +1),
53 if ($ip =~ m/^lin[01]$/) {
54 $i_offset = V( $lin_len * ($ip =~ m/1/ ? $it : 1-$it),
57 } elsif ($ip =~ m/^circle$/) {
58 $i_offset = V( 0,0,0 );
59 $i_outward = V( sin($it * TAU/2),
62 } elsif ($ip =~ m/^lin2$/) {
63 $i_offset = V( -$lin_len -$sine_len + $it*$lin2_len,
66 } elsif ($ip =~ m/^sine[01]$/) {
67 $i_offset = V( -$lin_len -$it*$sine_len,
69 $sine_height * ( 0.5 - 0.5*cos( $it*TAU/2 ) )
71 } elsif ($ip =~ m/^ball[02]$/) {
72 my $angle = ($ip =~ m/0/ ? (1-$it) : $it) * TAU/4;
73 $i_offset = V( -$lin_len -$sine_len
74 -($ip =~ m/2/ ? $lin2_len : 0)
75 -sin($angle) * $ballend_xr,
83 my $j_plus_th = $jp =~ m/2$/ ? $thick : 0;
85 my $i_thick = $thick * $i_thickscale;
86 my $j_p_x = $small_dia/2 + $thick;
87 my $j_rs_x = $large_dia/2 + $thick;
88 my $j_dqr_x = (1-cos($slope_angle)) * $jcurverad;
89 my $j_q_x = $j_rs_x - $j_dqr_x;
90 my $j_dpq = ($j_q_x - $j_p_x) / asin($slope_angle);
92 my $j_q_y = $j_p_y + $j_dpq * cos($slope_angle);
93 my $j_r_y = $j_q_y + sin($slope_angle) * $jcurverad;
95 my $j_qrc_x = $j_rs_x - $jcurverad;
98 if ($jp =~ m/^curveE$/) {
99 my $angle = ($jt + 1) * TAU/2 - $slope_angle;
100 $j_x = $j_p_x + $i_thick * cos($angle);
101 $j_y = $j_p_y + $i_thick * sin($angle);
102 } elsif ($jp =~ m/^curve[12]E$/) {
103 my $angle = $slope_angle * ($jp =~ m/1/ ? $jt : (1-$jt));
104 my $outwards = $jp =~ m/1/ ? -1 : +1;
105 $j_x = $j_qrc_x + cos($angle) * ($jcurverad + $outwards * $i_thick);
106 $j_y = $j_qrc_y + sin($angle) * ($jcurverad + $outwards * $i_thick);
107 } elsif ($jp =~ m/^lin0$/) {
108 $j_x = $j_rs_x + $i_thick * (-0.5 + 0.5 * jt);
119 sub get_sections_ptvals {
122 while (defined my $name = shift @_) {
124 push @out, [ $last_name, 1.0 ];
126 my $count = shift @_;
127 foreach (my $ix = 0; $ix < $count; $ix++) {
128 push @out, [ $name, $ix/$count ];
141 foreach my $pval (@_) {
142 my $pix = $point_indices{$pval}
143 //= ((push @points, $pval), $#points);
144 return if grep { $pix eq $_ } @pixs
147 push @triangles, \@pixs;
151 my @ipts = get_sections_ptvals(@i_sections);
152 my @jpts = get_sections_ptvals(@j_sections);
154 foreach my $ipt (@ipts) {
156 foreach my $jpt (@jpts) {
157 push @row, &point @$ipt, @$jpt;
161 foreach (my $qi=0; $qi<$#ipts; $qi++) { # i direction does not wrap
163 foreach (my $qj=0; $qj<@jpts; $qj++) { # j direction does wrap
164 my $qj2 = ($qj+1) % @jpts;
165 my $p0 = $sheet[$qi][$qj];
166 triangle($p0, $sheet[$qi2][$qj], $sheet[$qi2][$qj2]);
167 triangle($p0, $sheet[$qi2][$qj2], $sheet[$qi2][$qj2]);
173 print "polyhedron(points=[\n" or die $!;
174 print $_,",\n" or die $! foreach @points;
175 print "],triangles=[\n" or die $!;
176 print $_,",\n" or die $! foreach @triangles;
177 print "],convexity=10)\n" or die $!;