chiark / gitweb /
lemon-stand.scad.pl: channels wip
[reprap-play.git] / lemon-stand.scad.pl
index 84417f2377b54ea4fa1f3a8de058aaaddbb6e60b..048f4d7bdb6813ad3a4c4887c534d7d4ef3183f4 100755 (executable)
@@ -14,9 +14,11 @@ END
 
 my $ellipse = 20;
 my $circle = 6;
+my $channel = 5;
 my $xscale = 2;
 my $N = 30; # around ellipse
 my $M = 20; # around each circle
+my @channeldistprops = (0, 1/3, 2/3);
 
 our @ellipse = map {
     my $theta = tau * $_ / $N;
@@ -42,6 +44,11 @@ our @circles = map {
     } 0..($M-1) ];
 } 0..($N-1);
 
+sub scadvec ($) {
+    my ($v) = @_;
+    return "[ ".(join ", ", @$v)." ]"
+}
+
 sub torusy () {
     print "module Torusy(){ polyhedron(points=[";
     my $ptix = 0;
@@ -50,7 +57,7 @@ sub torusy () {
        foreach my $j (0..$M-1) {
            print "," if $ptix;
            print "\n";
-           print "    [ ", (join ", ", @{ $circles[$i][$j] }), " ]";
+           print "    ",(scadvec $circles[$i][$j]);
            $cirpt[$i][$j] = $ptix++;
        }
     }
@@ -80,6 +87,55 @@ sub torusy () {
 
 torusy();
 
+
+our @distances;
+push @distances, 0;
+foreach my $i (1..$N) {
+    my $dist = $distances[ $i-1 ];
+    $dist += abs($ellipse[$i % $N] - $ellipse[$i-1]);
+    $distances[$i] = $dist;
+}
+
+sub infodistprop ($) {
+    my ($distprop) = @_;
+    # returns
+    #   ( $ellipse_centreline_point,
+    #     $along_vector )
+    my $dist = $distprop * $distances[$N];
+    foreach my $i (0..$N-1) {
+       my $prorata =
+           ($dist - $distances[$i]) /
+           ($distances[$i+1] - $distances[$i]);
+       next unless 0 <= $prorata && $prorata <= 1;
+       print "// infodistprop $distprop => #$i=$ellipse[$i] $prorata $ellipse[$i+1]\n";
+       return (
+               (1-$prorata) * $ellipse[$i] + ($prorata) * $ellipse[$i+1],
+               $alongs[$i],
+              );
+    }
+    die "$distprop ?";
+}
+
+sub channels(){
+    print "module Channels(){\n";
+    
+    foreach my $cdp (
+                    (map { 0.5 *  $_    } @channeldistprops),
+                    (map { 0.5 * ($_+1) } @channeldistprops),
+                   ) {
+       my ($ctr, $along) = infodistprop($cdp);
+       my $angle = atan2(-$along->[0], $along->[1]);
+       print "  translate(",scadvec($ctr),")\n";
+       print "  rotate([0,0,$angle*360/",tau,"])\n";
+       print "  rotate([0,90,0])\n";
+       print "  translate([0,0, -2*$circle])\n";
+       print "  cylinder(r=$channel, h=4*$circle, \$fn=$M);\n";
+    }
+    print "}\n";
+}
+
+channels();
+
 while (<DATA>) { print };
 
 STDOUT->error and die $!;
@@ -87,3 +143,4 @@ STDOUT->flush or die $!;
 
 __DATA__
 Torusy();
+Channels();